Tue, 16 Mar 2010 11:52:17 +0100
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
Summary: Passing a null pointer to an InvokeDynamic function call should lead to a NullPointerException.
Reviewed-by: kvn, never
duke@435 | 1 | /* |
twisti@1734 | 2 | * Copyright 1998-2010 Sun Microsystems, Inc. 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 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | # include "incls/_precompiled.incl" |
duke@435 | 26 | # include "incls/_codeBlob.cpp.incl" |
duke@435 | 27 | |
duke@435 | 28 | unsigned int align_code_offset(int offset) { |
duke@435 | 29 | // align the size to CodeEntryAlignment |
duke@435 | 30 | return |
duke@435 | 31 | ((offset + (int)CodeHeap::header_size() + (CodeEntryAlignment-1)) & ~(CodeEntryAlignment-1)) |
duke@435 | 32 | - (int)CodeHeap::header_size(); |
duke@435 | 33 | } |
duke@435 | 34 | |
duke@435 | 35 | |
duke@435 | 36 | // This must be consistent with the CodeBlob constructor's layout actions. |
duke@435 | 37 | unsigned int CodeBlob::allocation_size(CodeBuffer* cb, int header_size) { |
duke@435 | 38 | unsigned int size = header_size; |
duke@435 | 39 | size += round_to(cb->total_relocation_size(), oopSize); |
duke@435 | 40 | // align the size to CodeEntryAlignment |
duke@435 | 41 | size = align_code_offset(size); |
duke@435 | 42 | size += round_to(cb->total_code_size(), oopSize); |
duke@435 | 43 | size += round_to(cb->total_oop_size(), oopSize); |
duke@435 | 44 | return size; |
duke@435 | 45 | } |
duke@435 | 46 | |
duke@435 | 47 | |
duke@435 | 48 | // Creates a simple CodeBlob. Sets up the size of the different regions. |
duke@435 | 49 | CodeBlob::CodeBlob(const char* name, int header_size, int size, int frame_complete, int locs_size) { |
duke@435 | 50 | assert(size == round_to(size, oopSize), "unaligned size"); |
duke@435 | 51 | assert(locs_size == round_to(locs_size, oopSize), "unaligned size"); |
duke@435 | 52 | assert(header_size == round_to(header_size, oopSize), "unaligned size"); |
duke@435 | 53 | assert(!UseRelocIndex, "no space allocated for reloc index yet"); |
duke@435 | 54 | |
duke@435 | 55 | // Note: If UseRelocIndex is enabled, there needs to be (at least) one |
duke@435 | 56 | // extra word for the relocation information, containing the reloc |
duke@435 | 57 | // index table length. Unfortunately, the reloc index table imple- |
duke@435 | 58 | // mentation is not easily understandable and thus it is not clear |
duke@435 | 59 | // what exactly the format is supposed to be. For now, we just turn |
duke@435 | 60 | // off the use of this table (gri 7/6/2000). |
duke@435 | 61 | |
duke@435 | 62 | _name = name; |
duke@435 | 63 | _size = size; |
duke@435 | 64 | _frame_complete_offset = frame_complete; |
duke@435 | 65 | _header_size = header_size; |
duke@435 | 66 | _relocation_size = locs_size; |
duke@435 | 67 | _instructions_offset = align_code_offset(header_size + locs_size); |
duke@435 | 68 | _data_offset = size; |
duke@435 | 69 | _oops_offset = size; |
duke@435 | 70 | _oops_length = 0; |
duke@435 | 71 | _frame_size = 0; |
duke@435 | 72 | set_oop_maps(NULL); |
duke@435 | 73 | } |
duke@435 | 74 | |
duke@435 | 75 | |
duke@435 | 76 | // Creates a CodeBlob from a CodeBuffer. Sets up the size of the different regions, |
duke@435 | 77 | // and copy code and relocation info. |
duke@435 | 78 | CodeBlob::CodeBlob( |
duke@435 | 79 | const char* name, |
duke@435 | 80 | CodeBuffer* cb, |
duke@435 | 81 | int header_size, |
duke@435 | 82 | int size, |
duke@435 | 83 | int frame_complete, |
duke@435 | 84 | int frame_size, |
duke@435 | 85 | OopMapSet* oop_maps |
duke@435 | 86 | ) { |
duke@435 | 87 | assert(size == round_to(size, oopSize), "unaligned size"); |
duke@435 | 88 | assert(header_size == round_to(header_size, oopSize), "unaligned size"); |
duke@435 | 89 | |
duke@435 | 90 | _name = name; |
duke@435 | 91 | _size = size; |
duke@435 | 92 | _frame_complete_offset = frame_complete; |
duke@435 | 93 | _header_size = header_size; |
duke@435 | 94 | _relocation_size = round_to(cb->total_relocation_size(), oopSize); |
duke@435 | 95 | _instructions_offset = align_code_offset(header_size + _relocation_size); |
duke@435 | 96 | _data_offset = _instructions_offset + round_to(cb->total_code_size(), oopSize); |
duke@435 | 97 | _oops_offset = _size - round_to(cb->total_oop_size(), oopSize); |
duke@435 | 98 | _oops_length = 0; // temporary, until the copy_oops handshake |
duke@435 | 99 | assert(_oops_offset >= _data_offset, "codeBlob is too small"); |
duke@435 | 100 | assert(_data_offset <= size, "codeBlob is too small"); |
duke@435 | 101 | |
duke@435 | 102 | cb->copy_code_and_locs_to(this); |
duke@435 | 103 | set_oop_maps(oop_maps); |
duke@435 | 104 | _frame_size = frame_size; |
duke@435 | 105 | #ifdef COMPILER1 |
duke@435 | 106 | // probably wrong for tiered |
duke@435 | 107 | assert(_frame_size >= -1, "must use frame size or -1 for runtime stubs"); |
duke@435 | 108 | #endif // COMPILER1 |
duke@435 | 109 | } |
duke@435 | 110 | |
duke@435 | 111 | |
duke@435 | 112 | void CodeBlob::set_oop_maps(OopMapSet* p) { |
duke@435 | 113 | // Danger Will Robinson! This method allocates a big |
duke@435 | 114 | // chunk of memory, its your job to free it. |
duke@435 | 115 | if (p != NULL) { |
duke@435 | 116 | // We need to allocate a chunk big enough to hold the OopMapSet and all of its OopMaps |
duke@435 | 117 | _oop_maps = (OopMapSet* )NEW_C_HEAP_ARRAY(unsigned char, p->heap_size()); |
duke@435 | 118 | p->copy_to((address)_oop_maps); |
duke@435 | 119 | } else { |
duke@435 | 120 | _oop_maps = NULL; |
duke@435 | 121 | } |
duke@435 | 122 | } |
duke@435 | 123 | |
duke@435 | 124 | |
duke@435 | 125 | void CodeBlob::flush() { |
duke@435 | 126 | if (_oop_maps) { |
duke@435 | 127 | FREE_C_HEAP_ARRAY(unsigned char, _oop_maps); |
duke@435 | 128 | _oop_maps = NULL; |
duke@435 | 129 | } |
duke@435 | 130 | _comments.free(); |
duke@435 | 131 | } |
duke@435 | 132 | |
duke@435 | 133 | |
duke@435 | 134 | // Promote one word from an assembly-time handle to a live embedded oop. |
duke@435 | 135 | inline void CodeBlob::initialize_immediate_oop(oop* dest, jobject handle) { |
duke@435 | 136 | if (handle == NULL || |
duke@435 | 137 | // As a special case, IC oops are initialized to 1 or -1. |
duke@435 | 138 | handle == (jobject) Universe::non_oop_word()) { |
duke@435 | 139 | (*dest) = (oop)handle; |
duke@435 | 140 | } else { |
duke@435 | 141 | (*dest) = JNIHandles::resolve_non_null(handle); |
duke@435 | 142 | } |
duke@435 | 143 | } |
duke@435 | 144 | |
duke@435 | 145 | |
duke@435 | 146 | void CodeBlob::copy_oops(GrowableArray<jobject>* array) { |
duke@435 | 147 | assert(_oops_length == 0, "do this handshake just once, please"); |
duke@435 | 148 | int length = array->length(); |
duke@435 | 149 | assert((address)(oops_begin() + length) <= data_end(), "oops big enough"); |
duke@435 | 150 | oop* dest = oops_begin(); |
duke@435 | 151 | for (int index = 0 ; index < length; index++) { |
duke@435 | 152 | initialize_immediate_oop(&dest[index], array->at(index)); |
duke@435 | 153 | } |
duke@435 | 154 | _oops_length = length; |
duke@435 | 155 | |
duke@435 | 156 | // Now we can fix up all the oops in the code. |
duke@435 | 157 | // We need to do this in the code because |
duke@435 | 158 | // the assembler uses jobjects as placeholders. |
duke@435 | 159 | // The code and relocations have already been |
duke@435 | 160 | // initialized by the CodeBlob constructor, |
duke@435 | 161 | // so it is valid even at this early point to |
duke@435 | 162 | // iterate over relocations and patch the code. |
duke@435 | 163 | fix_oop_relocations(NULL, NULL, /*initialize_immediates=*/ true); |
duke@435 | 164 | } |
duke@435 | 165 | |
duke@435 | 166 | |
duke@435 | 167 | relocInfo::relocType CodeBlob::reloc_type_for_address(address pc) { |
duke@435 | 168 | RelocIterator iter(this, pc, pc+1); |
duke@435 | 169 | while (iter.next()) { |
duke@435 | 170 | return (relocInfo::relocType) iter.type(); |
duke@435 | 171 | } |
duke@435 | 172 | // No relocation info found for pc |
duke@435 | 173 | ShouldNotReachHere(); |
duke@435 | 174 | return relocInfo::none; // dummy return value |
duke@435 | 175 | } |
duke@435 | 176 | |
duke@435 | 177 | |
duke@435 | 178 | bool CodeBlob::is_at_poll_return(address pc) { |
duke@435 | 179 | RelocIterator iter(this, pc, pc+1); |
duke@435 | 180 | while (iter.next()) { |
duke@435 | 181 | if (iter.type() == relocInfo::poll_return_type) |
duke@435 | 182 | return true; |
duke@435 | 183 | } |
duke@435 | 184 | return false; |
duke@435 | 185 | } |
duke@435 | 186 | |
duke@435 | 187 | |
duke@435 | 188 | bool CodeBlob::is_at_poll_or_poll_return(address pc) { |
duke@435 | 189 | RelocIterator iter(this, pc, pc+1); |
duke@435 | 190 | while (iter.next()) { |
duke@435 | 191 | relocInfo::relocType t = iter.type(); |
duke@435 | 192 | if (t == relocInfo::poll_return_type || t == relocInfo::poll_type) |
duke@435 | 193 | return true; |
duke@435 | 194 | } |
duke@435 | 195 | return false; |
duke@435 | 196 | } |
duke@435 | 197 | |
duke@435 | 198 | |
duke@435 | 199 | void CodeBlob::fix_oop_relocations(address begin, address end, |
duke@435 | 200 | bool initialize_immediates) { |
duke@435 | 201 | // re-patch all oop-bearing instructions, just in case some oops moved |
duke@435 | 202 | RelocIterator iter(this, begin, end); |
duke@435 | 203 | while (iter.next()) { |
duke@435 | 204 | if (iter.type() == relocInfo::oop_type) { |
duke@435 | 205 | oop_Relocation* reloc = iter.oop_reloc(); |
duke@435 | 206 | if (initialize_immediates && reloc->oop_is_immediate()) { |
duke@435 | 207 | oop* dest = reloc->oop_addr(); |
duke@435 | 208 | initialize_immediate_oop(dest, (jobject) *dest); |
duke@435 | 209 | } |
duke@435 | 210 | // Refresh the oop-related bits of this instruction. |
duke@435 | 211 | reloc->fix_oop_relocation(); |
duke@435 | 212 | } |
duke@435 | 213 | |
duke@435 | 214 | // There must not be any interfering patches or breakpoints. |
duke@435 | 215 | assert(!(iter.type() == relocInfo::breakpoint_type |
duke@435 | 216 | && iter.breakpoint_reloc()->active()), |
duke@435 | 217 | "no active breakpoint"); |
duke@435 | 218 | } |
duke@435 | 219 | } |
duke@435 | 220 | |
duke@435 | 221 | void CodeBlob::do_unloading(BoolObjectClosure* is_alive, |
duke@435 | 222 | OopClosure* keep_alive, |
duke@435 | 223 | bool unloading_occurred) { |
duke@435 | 224 | ShouldNotReachHere(); |
duke@435 | 225 | } |
duke@435 | 226 | |
duke@435 | 227 | OopMap* CodeBlob::oop_map_for_return_address(address return_address) { |
duke@435 | 228 | address pc = return_address ; |
duke@435 | 229 | assert (oop_maps() != NULL, "nope"); |
duke@435 | 230 | return oop_maps()->find_map_at_offset ((intptr_t) pc - (intptr_t) instructions_begin()); |
duke@435 | 231 | } |
duke@435 | 232 | |
duke@435 | 233 | |
duke@435 | 234 | //---------------------------------------------------------------------------------------------------- |
duke@435 | 235 | // Implementation of BufferBlob |
duke@435 | 236 | |
duke@435 | 237 | |
duke@435 | 238 | BufferBlob::BufferBlob(const char* name, int size) |
duke@435 | 239 | : CodeBlob(name, sizeof(BufferBlob), size, CodeOffsets::frame_never_safe, /*locs_size:*/ 0) |
duke@435 | 240 | {} |
duke@435 | 241 | |
duke@435 | 242 | BufferBlob* BufferBlob::create(const char* name, int buffer_size) { |
duke@435 | 243 | ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock |
duke@435 | 244 | |
duke@435 | 245 | BufferBlob* blob = NULL; |
duke@435 | 246 | unsigned int size = sizeof(BufferBlob); |
duke@435 | 247 | // align the size to CodeEntryAlignment |
duke@435 | 248 | size = align_code_offset(size); |
duke@435 | 249 | size += round_to(buffer_size, oopSize); |
duke@435 | 250 | assert(name != NULL, "must provide a name"); |
duke@435 | 251 | { |
duke@435 | 252 | MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
duke@435 | 253 | blob = new (size) BufferBlob(name, size); |
duke@435 | 254 | } |
duke@435 | 255 | // Track memory usage statistic after releasing CodeCache_lock |
duke@435 | 256 | MemoryService::track_code_cache_memory_usage(); |
duke@435 | 257 | |
duke@435 | 258 | return blob; |
duke@435 | 259 | } |
duke@435 | 260 | |
duke@435 | 261 | |
duke@435 | 262 | BufferBlob::BufferBlob(const char* name, int size, CodeBuffer* cb) |
duke@435 | 263 | : CodeBlob(name, cb, sizeof(BufferBlob), size, CodeOffsets::frame_never_safe, 0, NULL) |
duke@435 | 264 | {} |
duke@435 | 265 | |
duke@435 | 266 | BufferBlob* BufferBlob::create(const char* name, CodeBuffer* cb) { |
duke@435 | 267 | ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock |
duke@435 | 268 | |
duke@435 | 269 | BufferBlob* blob = NULL; |
duke@435 | 270 | unsigned int size = allocation_size(cb, sizeof(BufferBlob)); |
duke@435 | 271 | assert(name != NULL, "must provide a name"); |
duke@435 | 272 | { |
duke@435 | 273 | MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
duke@435 | 274 | blob = new (size) BufferBlob(name, size, cb); |
duke@435 | 275 | } |
duke@435 | 276 | // Track memory usage statistic after releasing CodeCache_lock |
duke@435 | 277 | MemoryService::track_code_cache_memory_usage(); |
duke@435 | 278 | |
duke@435 | 279 | return blob; |
duke@435 | 280 | } |
duke@435 | 281 | |
duke@435 | 282 | |
duke@435 | 283 | void* BufferBlob::operator new(size_t s, unsigned size) { |
duke@435 | 284 | void* p = CodeCache::allocate(size); |
duke@435 | 285 | return p; |
duke@435 | 286 | } |
duke@435 | 287 | |
duke@435 | 288 | |
duke@435 | 289 | void BufferBlob::free( BufferBlob *blob ) { |
duke@435 | 290 | ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock |
duke@435 | 291 | { |
duke@435 | 292 | MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
duke@435 | 293 | CodeCache::free((CodeBlob*)blob); |
duke@435 | 294 | } |
duke@435 | 295 | // Track memory usage statistic after releasing CodeCache_lock |
duke@435 | 296 | MemoryService::track_code_cache_memory_usage(); |
duke@435 | 297 | } |
duke@435 | 298 | |
twisti@1734 | 299 | |
twisti@1734 | 300 | //---------------------------------------------------------------------------------------------------- |
twisti@1734 | 301 | // Implementation of AdapterBlob |
twisti@1734 | 302 | |
twisti@1734 | 303 | AdapterBlob* AdapterBlob::create(CodeBuffer* cb) { |
twisti@1734 | 304 | ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock |
twisti@1734 | 305 | |
twisti@1734 | 306 | AdapterBlob* blob = NULL; |
twisti@1734 | 307 | unsigned int size = allocation_size(cb, sizeof(AdapterBlob)); |
twisti@1734 | 308 | { |
twisti@1734 | 309 | MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
twisti@1734 | 310 | blob = new (size) AdapterBlob(size, cb); |
twisti@1734 | 311 | } |
twisti@1734 | 312 | // Track memory usage statistic after releasing CodeCache_lock |
twisti@1734 | 313 | MemoryService::track_code_cache_memory_usage(); |
twisti@1734 | 314 | |
twisti@1734 | 315 | return blob; |
duke@435 | 316 | } |
duke@435 | 317 | |
twisti@1734 | 318 | |
twisti@1734 | 319 | //---------------------------------------------------------------------------------------------------- |
twisti@1734 | 320 | // Implementation of MethodHandlesAdapterBlob |
twisti@1734 | 321 | |
twisti@1734 | 322 | MethodHandlesAdapterBlob* MethodHandlesAdapterBlob::create(int buffer_size) { |
twisti@1734 | 323 | ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock |
twisti@1734 | 324 | |
twisti@1734 | 325 | MethodHandlesAdapterBlob* blob = NULL; |
twisti@1734 | 326 | unsigned int size = sizeof(MethodHandlesAdapterBlob); |
twisti@1734 | 327 | // align the size to CodeEntryAlignment |
twisti@1734 | 328 | size = align_code_offset(size); |
twisti@1734 | 329 | size += round_to(buffer_size, oopSize); |
twisti@1734 | 330 | { |
twisti@1734 | 331 | MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
twisti@1734 | 332 | blob = new (size) MethodHandlesAdapterBlob(size); |
twisti@1734 | 333 | } |
twisti@1734 | 334 | // Track memory usage statistic after releasing CodeCache_lock |
twisti@1734 | 335 | MemoryService::track_code_cache_memory_usage(); |
twisti@1734 | 336 | |
twisti@1734 | 337 | return blob; |
twisti@1734 | 338 | } |
twisti@1734 | 339 | |
twisti@1734 | 340 | |
duke@435 | 341 | //---------------------------------------------------------------------------------------------------- |
duke@435 | 342 | // Implementation of RuntimeStub |
duke@435 | 343 | |
duke@435 | 344 | RuntimeStub::RuntimeStub( |
duke@435 | 345 | const char* name, |
duke@435 | 346 | CodeBuffer* cb, |
duke@435 | 347 | int size, |
duke@435 | 348 | int frame_complete, |
duke@435 | 349 | int frame_size, |
duke@435 | 350 | OopMapSet* oop_maps, |
duke@435 | 351 | bool caller_must_gc_arguments |
duke@435 | 352 | ) |
duke@435 | 353 | : CodeBlob(name, cb, sizeof(RuntimeStub), size, frame_complete, frame_size, oop_maps) |
duke@435 | 354 | { |
duke@435 | 355 | _caller_must_gc_arguments = caller_must_gc_arguments; |
duke@435 | 356 | } |
duke@435 | 357 | |
duke@435 | 358 | |
duke@435 | 359 | RuntimeStub* RuntimeStub::new_runtime_stub(const char* stub_name, |
duke@435 | 360 | CodeBuffer* cb, |
duke@435 | 361 | int frame_complete, |
duke@435 | 362 | int frame_size, |
duke@435 | 363 | OopMapSet* oop_maps, |
duke@435 | 364 | bool caller_must_gc_arguments) |
duke@435 | 365 | { |
duke@435 | 366 | RuntimeStub* stub = NULL; |
duke@435 | 367 | ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock |
duke@435 | 368 | { |
duke@435 | 369 | MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
duke@435 | 370 | unsigned int size = allocation_size(cb, sizeof(RuntimeStub)); |
duke@435 | 371 | stub = new (size) RuntimeStub(stub_name, cb, size, frame_complete, frame_size, oop_maps, caller_must_gc_arguments); |
duke@435 | 372 | } |
duke@435 | 373 | |
duke@435 | 374 | // Do not hold the CodeCache lock during name formatting. |
duke@435 | 375 | if (stub != NULL) { |
duke@435 | 376 | char stub_id[256]; |
duke@435 | 377 | jio_snprintf(stub_id, sizeof(stub_id), "RuntimeStub - %s", stub_name); |
duke@435 | 378 | if (PrintStubCode) { |
duke@435 | 379 | tty->print_cr("Decoding %s " INTPTR_FORMAT, stub_id, stub); |
duke@435 | 380 | Disassembler::decode(stub->instructions_begin(), stub->instructions_end()); |
duke@435 | 381 | } |
duke@435 | 382 | VTune::register_stub(stub_id, stub->instructions_begin(), stub->instructions_end()); |
duke@435 | 383 | Forte::register_stub(stub_id, stub->instructions_begin(), stub->instructions_end()); |
duke@435 | 384 | |
duke@435 | 385 | if (JvmtiExport::should_post_dynamic_code_generated()) { |
duke@435 | 386 | JvmtiExport::post_dynamic_code_generated(stub_name, stub->instructions_begin(), stub->instructions_end()); |
duke@435 | 387 | } |
duke@435 | 388 | } |
duke@435 | 389 | |
duke@435 | 390 | // Track memory usage statistic after releasing CodeCache_lock |
duke@435 | 391 | MemoryService::track_code_cache_memory_usage(); |
duke@435 | 392 | |
duke@435 | 393 | return stub; |
duke@435 | 394 | } |
duke@435 | 395 | |
duke@435 | 396 | |
duke@435 | 397 | void* RuntimeStub::operator new(size_t s, unsigned size) { |
duke@435 | 398 | void* p = CodeCache::allocate(size); |
duke@435 | 399 | if (!p) fatal("Initial size of CodeCache is too small"); |
duke@435 | 400 | return p; |
duke@435 | 401 | } |
duke@435 | 402 | |
duke@435 | 403 | |
duke@435 | 404 | //---------------------------------------------------------------------------------------------------- |
duke@435 | 405 | // Implementation of DeoptimizationBlob |
duke@435 | 406 | |
duke@435 | 407 | DeoptimizationBlob::DeoptimizationBlob( |
duke@435 | 408 | CodeBuffer* cb, |
duke@435 | 409 | int size, |
duke@435 | 410 | OopMapSet* oop_maps, |
duke@435 | 411 | int unpack_offset, |
duke@435 | 412 | int unpack_with_exception_offset, |
duke@435 | 413 | int unpack_with_reexecution_offset, |
duke@435 | 414 | int frame_size |
duke@435 | 415 | ) |
duke@435 | 416 | : SingletonBlob("DeoptimizationBlob", cb, sizeof(DeoptimizationBlob), size, frame_size, oop_maps) |
duke@435 | 417 | { |
duke@435 | 418 | _unpack_offset = unpack_offset; |
duke@435 | 419 | _unpack_with_exception = unpack_with_exception_offset; |
duke@435 | 420 | _unpack_with_reexecution = unpack_with_reexecution_offset; |
duke@435 | 421 | #ifdef COMPILER1 |
duke@435 | 422 | _unpack_with_exception_in_tls = -1; |
duke@435 | 423 | #endif |
duke@435 | 424 | } |
duke@435 | 425 | |
duke@435 | 426 | |
duke@435 | 427 | DeoptimizationBlob* DeoptimizationBlob::create( |
duke@435 | 428 | CodeBuffer* cb, |
duke@435 | 429 | OopMapSet* oop_maps, |
duke@435 | 430 | int unpack_offset, |
duke@435 | 431 | int unpack_with_exception_offset, |
duke@435 | 432 | int unpack_with_reexecution_offset, |
duke@435 | 433 | int frame_size) |
duke@435 | 434 | { |
duke@435 | 435 | DeoptimizationBlob* blob = NULL; |
duke@435 | 436 | ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock |
duke@435 | 437 | { |
duke@435 | 438 | MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
duke@435 | 439 | unsigned int size = allocation_size(cb, sizeof(DeoptimizationBlob)); |
duke@435 | 440 | blob = new (size) DeoptimizationBlob(cb, |
duke@435 | 441 | size, |
duke@435 | 442 | oop_maps, |
duke@435 | 443 | unpack_offset, |
duke@435 | 444 | unpack_with_exception_offset, |
duke@435 | 445 | unpack_with_reexecution_offset, |
duke@435 | 446 | frame_size); |
duke@435 | 447 | } |
duke@435 | 448 | |
duke@435 | 449 | // Do not hold the CodeCache lock during name formatting. |
duke@435 | 450 | if (blob != NULL) { |
duke@435 | 451 | char blob_id[256]; |
duke@435 | 452 | jio_snprintf(blob_id, sizeof(blob_id), "DeoptimizationBlob@" PTR_FORMAT, blob->instructions_begin()); |
duke@435 | 453 | if (PrintStubCode) { |
duke@435 | 454 | tty->print_cr("Decoding %s " INTPTR_FORMAT, blob_id, blob); |
duke@435 | 455 | Disassembler::decode(blob->instructions_begin(), blob->instructions_end()); |
duke@435 | 456 | } |
duke@435 | 457 | VTune::register_stub(blob_id, blob->instructions_begin(), blob->instructions_end()); |
duke@435 | 458 | Forte::register_stub(blob_id, blob->instructions_begin(), blob->instructions_end()); |
duke@435 | 459 | |
duke@435 | 460 | if (JvmtiExport::should_post_dynamic_code_generated()) { |
duke@435 | 461 | JvmtiExport::post_dynamic_code_generated("DeoptimizationBlob", |
duke@435 | 462 | blob->instructions_begin(), |
duke@435 | 463 | blob->instructions_end()); |
duke@435 | 464 | } |
duke@435 | 465 | } |
duke@435 | 466 | |
duke@435 | 467 | // Track memory usage statistic after releasing CodeCache_lock |
duke@435 | 468 | MemoryService::track_code_cache_memory_usage(); |
duke@435 | 469 | |
duke@435 | 470 | return blob; |
duke@435 | 471 | } |
duke@435 | 472 | |
duke@435 | 473 | |
duke@435 | 474 | void* DeoptimizationBlob::operator new(size_t s, unsigned size) { |
duke@435 | 475 | void* p = CodeCache::allocate(size); |
duke@435 | 476 | if (!p) fatal("Initial size of CodeCache is too small"); |
duke@435 | 477 | return p; |
duke@435 | 478 | } |
duke@435 | 479 | |
duke@435 | 480 | //---------------------------------------------------------------------------------------------------- |
duke@435 | 481 | // Implementation of UncommonTrapBlob |
duke@435 | 482 | |
duke@435 | 483 | #ifdef COMPILER2 |
duke@435 | 484 | UncommonTrapBlob::UncommonTrapBlob( |
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 | : SingletonBlob("UncommonTrapBlob", cb, sizeof(UncommonTrapBlob), size, frame_size, oop_maps) |
duke@435 | 491 | {} |
duke@435 | 492 | |
duke@435 | 493 | |
duke@435 | 494 | UncommonTrapBlob* UncommonTrapBlob::create( |
duke@435 | 495 | CodeBuffer* cb, |
duke@435 | 496 | OopMapSet* oop_maps, |
duke@435 | 497 | int frame_size) |
duke@435 | 498 | { |
duke@435 | 499 | UncommonTrapBlob* blob = NULL; |
duke@435 | 500 | ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock |
duke@435 | 501 | { |
duke@435 | 502 | MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
duke@435 | 503 | unsigned int size = allocation_size(cb, sizeof(UncommonTrapBlob)); |
duke@435 | 504 | blob = new (size) UncommonTrapBlob(cb, size, oop_maps, frame_size); |
duke@435 | 505 | } |
duke@435 | 506 | |
duke@435 | 507 | // Do not hold the CodeCache lock during name formatting. |
duke@435 | 508 | if (blob != NULL) { |
duke@435 | 509 | char blob_id[256]; |
duke@435 | 510 | jio_snprintf(blob_id, sizeof(blob_id), "UncommonTrapBlob@" PTR_FORMAT, blob->instructions_begin()); |
duke@435 | 511 | if (PrintStubCode) { |
duke@435 | 512 | tty->print_cr("Decoding %s " INTPTR_FORMAT, blob_id, blob); |
duke@435 | 513 | Disassembler::decode(blob->instructions_begin(), blob->instructions_end()); |
duke@435 | 514 | } |
duke@435 | 515 | VTune::register_stub(blob_id, blob->instructions_begin(), blob->instructions_end()); |
duke@435 | 516 | Forte::register_stub(blob_id, blob->instructions_begin(), blob->instructions_end()); |
duke@435 | 517 | |
duke@435 | 518 | if (JvmtiExport::should_post_dynamic_code_generated()) { |
duke@435 | 519 | JvmtiExport::post_dynamic_code_generated("UncommonTrapBlob", |
duke@435 | 520 | blob->instructions_begin(), |
duke@435 | 521 | blob->instructions_end()); |
duke@435 | 522 | } |
duke@435 | 523 | } |
duke@435 | 524 | |
duke@435 | 525 | // Track memory usage statistic after releasing CodeCache_lock |
duke@435 | 526 | MemoryService::track_code_cache_memory_usage(); |
duke@435 | 527 | |
duke@435 | 528 | return blob; |
duke@435 | 529 | } |
duke@435 | 530 | |
duke@435 | 531 | |
duke@435 | 532 | void* UncommonTrapBlob::operator new(size_t s, unsigned size) { |
duke@435 | 533 | void* p = CodeCache::allocate(size); |
duke@435 | 534 | if (!p) fatal("Initial size of CodeCache is too small"); |
duke@435 | 535 | return p; |
duke@435 | 536 | } |
duke@435 | 537 | #endif // COMPILER2 |
duke@435 | 538 | |
duke@435 | 539 | |
duke@435 | 540 | //---------------------------------------------------------------------------------------------------- |
duke@435 | 541 | // Implementation of ExceptionBlob |
duke@435 | 542 | |
duke@435 | 543 | #ifdef COMPILER2 |
duke@435 | 544 | ExceptionBlob::ExceptionBlob( |
duke@435 | 545 | CodeBuffer* cb, |
duke@435 | 546 | int size, |
duke@435 | 547 | OopMapSet* oop_maps, |
duke@435 | 548 | int frame_size |
duke@435 | 549 | ) |
duke@435 | 550 | : SingletonBlob("ExceptionBlob", cb, sizeof(ExceptionBlob), size, frame_size, oop_maps) |
duke@435 | 551 | {} |
duke@435 | 552 | |
duke@435 | 553 | |
duke@435 | 554 | ExceptionBlob* ExceptionBlob::create( |
duke@435 | 555 | CodeBuffer* cb, |
duke@435 | 556 | OopMapSet* oop_maps, |
duke@435 | 557 | int frame_size) |
duke@435 | 558 | { |
duke@435 | 559 | ExceptionBlob* blob = NULL; |
duke@435 | 560 | ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock |
duke@435 | 561 | { |
duke@435 | 562 | MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
duke@435 | 563 | unsigned int size = allocation_size(cb, sizeof(ExceptionBlob)); |
duke@435 | 564 | blob = new (size) ExceptionBlob(cb, size, oop_maps, frame_size); |
duke@435 | 565 | } |
duke@435 | 566 | |
duke@435 | 567 | // We do not need to hold the CodeCache lock during name formatting |
duke@435 | 568 | if (blob != NULL) { |
duke@435 | 569 | char blob_id[256]; |
duke@435 | 570 | jio_snprintf(blob_id, sizeof(blob_id), "ExceptionBlob@" PTR_FORMAT, blob->instructions_begin()); |
duke@435 | 571 | if (PrintStubCode) { |
duke@435 | 572 | tty->print_cr("Decoding %s " INTPTR_FORMAT, blob_id, blob); |
duke@435 | 573 | Disassembler::decode(blob->instructions_begin(), blob->instructions_end()); |
duke@435 | 574 | } |
duke@435 | 575 | VTune::register_stub(blob_id, blob->instructions_begin(), blob->instructions_end()); |
duke@435 | 576 | Forte::register_stub(blob_id, blob->instructions_begin(), blob->instructions_end()); |
duke@435 | 577 | |
duke@435 | 578 | if (JvmtiExport::should_post_dynamic_code_generated()) { |
duke@435 | 579 | JvmtiExport::post_dynamic_code_generated("ExceptionBlob", |
duke@435 | 580 | blob->instructions_begin(), |
duke@435 | 581 | blob->instructions_end()); |
duke@435 | 582 | } |
duke@435 | 583 | } |
duke@435 | 584 | |
duke@435 | 585 | // Track memory usage statistic after releasing CodeCache_lock |
duke@435 | 586 | MemoryService::track_code_cache_memory_usage(); |
duke@435 | 587 | |
duke@435 | 588 | return blob; |
duke@435 | 589 | } |
duke@435 | 590 | |
duke@435 | 591 | |
duke@435 | 592 | void* ExceptionBlob::operator new(size_t s, unsigned size) { |
duke@435 | 593 | void* p = CodeCache::allocate(size); |
duke@435 | 594 | if (!p) fatal("Initial size of CodeCache is too small"); |
duke@435 | 595 | return p; |
duke@435 | 596 | } |
duke@435 | 597 | #endif // COMPILER2 |
duke@435 | 598 | |
duke@435 | 599 | |
duke@435 | 600 | //---------------------------------------------------------------------------------------------------- |
duke@435 | 601 | // Implementation of SafepointBlob |
duke@435 | 602 | |
duke@435 | 603 | SafepointBlob::SafepointBlob( |
duke@435 | 604 | CodeBuffer* cb, |
duke@435 | 605 | int size, |
duke@435 | 606 | OopMapSet* oop_maps, |
duke@435 | 607 | int frame_size |
duke@435 | 608 | ) |
duke@435 | 609 | : SingletonBlob("SafepointBlob", cb, sizeof(SafepointBlob), size, frame_size, oop_maps) |
duke@435 | 610 | {} |
duke@435 | 611 | |
duke@435 | 612 | |
duke@435 | 613 | SafepointBlob* SafepointBlob::create( |
duke@435 | 614 | CodeBuffer* cb, |
duke@435 | 615 | OopMapSet* oop_maps, |
duke@435 | 616 | int frame_size) |
duke@435 | 617 | { |
duke@435 | 618 | SafepointBlob* blob = NULL; |
duke@435 | 619 | ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock |
duke@435 | 620 | { |
duke@435 | 621 | MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
duke@435 | 622 | unsigned int size = allocation_size(cb, sizeof(SafepointBlob)); |
duke@435 | 623 | blob = new (size) SafepointBlob(cb, size, oop_maps, frame_size); |
duke@435 | 624 | } |
duke@435 | 625 | |
duke@435 | 626 | // We do not need to hold the CodeCache lock during name formatting. |
duke@435 | 627 | if (blob != NULL) { |
duke@435 | 628 | char blob_id[256]; |
duke@435 | 629 | jio_snprintf(blob_id, sizeof(blob_id), "SafepointBlob@" PTR_FORMAT, blob->instructions_begin()); |
duke@435 | 630 | if (PrintStubCode) { |
duke@435 | 631 | tty->print_cr("Decoding %s " INTPTR_FORMAT, blob_id, blob); |
duke@435 | 632 | Disassembler::decode(blob->instructions_begin(), blob->instructions_end()); |
duke@435 | 633 | } |
duke@435 | 634 | VTune::register_stub(blob_id, blob->instructions_begin(), blob->instructions_end()); |
duke@435 | 635 | Forte::register_stub(blob_id, blob->instructions_begin(), blob->instructions_end()); |
duke@435 | 636 | |
duke@435 | 637 | if (JvmtiExport::should_post_dynamic_code_generated()) { |
duke@435 | 638 | JvmtiExport::post_dynamic_code_generated("SafepointBlob", |
duke@435 | 639 | blob->instructions_begin(), |
duke@435 | 640 | blob->instructions_end()); |
duke@435 | 641 | } |
duke@435 | 642 | } |
duke@435 | 643 | |
duke@435 | 644 | // Track memory usage statistic after releasing CodeCache_lock |
duke@435 | 645 | MemoryService::track_code_cache_memory_usage(); |
duke@435 | 646 | |
duke@435 | 647 | return blob; |
duke@435 | 648 | } |
duke@435 | 649 | |
duke@435 | 650 | |
duke@435 | 651 | void* SafepointBlob::operator new(size_t s, unsigned size) { |
duke@435 | 652 | void* p = CodeCache::allocate(size); |
duke@435 | 653 | if (!p) fatal("Initial size of CodeCache is too small"); |
duke@435 | 654 | return p; |
duke@435 | 655 | } |
duke@435 | 656 | |
duke@435 | 657 | |
duke@435 | 658 | //---------------------------------------------------------------------------------------------------- |
duke@435 | 659 | // Verification and printing |
duke@435 | 660 | |
duke@435 | 661 | void CodeBlob::verify() { |
duke@435 | 662 | ShouldNotReachHere(); |
duke@435 | 663 | } |
duke@435 | 664 | |
duke@435 | 665 | #ifndef PRODUCT |
duke@435 | 666 | |
duke@435 | 667 | void CodeBlob::print() const { |
duke@435 | 668 | tty->print_cr("[CodeBlob (" INTPTR_FORMAT ")]", this); |
duke@435 | 669 | tty->print_cr("Framesize: %d", _frame_size); |
duke@435 | 670 | } |
duke@435 | 671 | |
duke@435 | 672 | |
duke@435 | 673 | void CodeBlob::print_value_on(outputStream* st) const { |
duke@435 | 674 | st->print_cr("[CodeBlob]"); |
duke@435 | 675 | } |
duke@435 | 676 | |
duke@435 | 677 | #endif |
duke@435 | 678 | |
duke@435 | 679 | void BufferBlob::verify() { |
duke@435 | 680 | // unimplemented |
duke@435 | 681 | } |
duke@435 | 682 | |
duke@435 | 683 | #ifndef PRODUCT |
duke@435 | 684 | |
duke@435 | 685 | void BufferBlob::print() const { |
duke@435 | 686 | CodeBlob::print(); |
duke@435 | 687 | print_value_on(tty); |
duke@435 | 688 | } |
duke@435 | 689 | |
duke@435 | 690 | |
duke@435 | 691 | void BufferBlob::print_value_on(outputStream* st) const { |
duke@435 | 692 | st->print_cr("BufferBlob (" INTPTR_FORMAT ") used for %s", this, name()); |
duke@435 | 693 | } |
duke@435 | 694 | |
duke@435 | 695 | |
duke@435 | 696 | #endif |
duke@435 | 697 | |
duke@435 | 698 | void RuntimeStub::verify() { |
duke@435 | 699 | // unimplemented |
duke@435 | 700 | } |
duke@435 | 701 | |
duke@435 | 702 | #ifndef PRODUCT |
duke@435 | 703 | |
duke@435 | 704 | void RuntimeStub::print() const { |
duke@435 | 705 | CodeBlob::print(); |
duke@435 | 706 | tty->print("Runtime Stub (" INTPTR_FORMAT "): ", this); |
duke@435 | 707 | tty->print_cr(name()); |
duke@435 | 708 | Disassembler::decode((CodeBlob*)this); |
duke@435 | 709 | } |
duke@435 | 710 | |
duke@435 | 711 | |
duke@435 | 712 | void RuntimeStub::print_value_on(outputStream* st) const { |
duke@435 | 713 | st->print("RuntimeStub (" INTPTR_FORMAT "): ", this); st->print(name()); |
duke@435 | 714 | } |
duke@435 | 715 | |
duke@435 | 716 | #endif |
duke@435 | 717 | |
duke@435 | 718 | void SingletonBlob::verify() { |
duke@435 | 719 | // unimplemented |
duke@435 | 720 | } |
duke@435 | 721 | |
duke@435 | 722 | #ifndef PRODUCT |
duke@435 | 723 | |
duke@435 | 724 | void SingletonBlob::print() const { |
duke@435 | 725 | CodeBlob::print(); |
duke@435 | 726 | tty->print_cr(name()); |
duke@435 | 727 | Disassembler::decode((CodeBlob*)this); |
duke@435 | 728 | } |
duke@435 | 729 | |
duke@435 | 730 | |
duke@435 | 731 | void SingletonBlob::print_value_on(outputStream* st) const { |
duke@435 | 732 | st->print_cr(name()); |
duke@435 | 733 | } |
duke@435 | 734 | |
duke@435 | 735 | void DeoptimizationBlob::print_value_on(outputStream* st) const { |
duke@435 | 736 | st->print_cr("Deoptimization (frame not available)"); |
duke@435 | 737 | } |
duke@435 | 738 | |
duke@435 | 739 | #endif // PRODUCT |