8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "code/codeBlob.hpp"
27 #include "code/codeCache.hpp"
28 #include "code/codeCacheExtensions.hpp"
29 #include "code/relocInfo.hpp"
30 #include "compiler/disassembler.hpp"
31 #include "interpreter/bytecode.hpp"
32 #include "memory/allocation.inline.hpp"
33 #include "memory/heap.hpp"
34 #include "memory/resourceArea.hpp"
35 #include "oops/oop.inline.hpp"
36 #include "prims/forte.hpp"
37 #include "runtime/handles.inline.hpp"
38 #include "runtime/interfaceSupport.hpp"
39 #include "runtime/mutexLocker.hpp"
40 #include "runtime/safepoint.hpp"
41 #include "runtime/sharedRuntime.hpp"
42 #include "runtime/vframe.hpp"
43 #include "services/memoryService.hpp"
44 #ifdef COMPILER1
45 #include "c1/c1_Runtime1.hpp"
46 #endif
47
48 const char* CodeBlob::compiler_name() const {
211
212 void CodeBlob::print_code() {
213 HandleMark hm;
214 ResourceMark m;
215 Disassembler::decode(this, tty);
216 }
217
218 //----------------------------------------------------------------------------------------------------
219 // Implementation of BufferBlob
220
221
222 BufferBlob::BufferBlob(const char* name, int size)
223 : RuntimeBlob(name, sizeof(BufferBlob), size, CodeOffsets::frame_never_safe, /*locs_size:*/ 0)
224 {}
225
226 BufferBlob* BufferBlob::create(const char* name, int buffer_size) {
227 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
228
229 BufferBlob* blob = NULL;
230 unsigned int size = sizeof(BufferBlob);
231 CodeCacheExtensions::size_blob(name, &buffer_size);
232 // align the size to CodeEntryAlignment
233 size = CodeBlob::align_code_offset(size);
234 size += round_to(buffer_size, oopSize);
235 assert(name != NULL, "must provide a name");
236 {
237 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
238 blob = new (size) BufferBlob(name, size);
239 }
240 // Track memory usage statistic after releasing CodeCache_lock
241 MemoryService::track_code_cache_memory_usage();
242
243 return blob;
244 }
245
246
247 BufferBlob::BufferBlob(const char* name, int size, CodeBuffer* cb)
248 : RuntimeBlob(name, cb, sizeof(BufferBlob), size, CodeOffsets::frame_never_safe, 0, NULL)
249 {}
250
251 BufferBlob* BufferBlob::create(const char* name, CodeBuffer* cb) {
295 unsigned int size = CodeBlob::allocation_size(cb, sizeof(AdapterBlob));
296 {
297 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
298 blob = new (size) AdapterBlob(size, cb);
299 }
300 // Track memory usage statistic after releasing CodeCache_lock
301 MemoryService::track_code_cache_memory_usage();
302
303 return blob;
304 }
305
306
307 //----------------------------------------------------------------------------------------------------
308 // Implementation of MethodHandlesAdapterBlob
309
310 MethodHandlesAdapterBlob* MethodHandlesAdapterBlob::create(int buffer_size) {
311 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
312
313 MethodHandlesAdapterBlob* blob = NULL;
314 unsigned int size = sizeof(MethodHandlesAdapterBlob);
315 CodeCacheExtensions::size_blob("MethodHandles adapters", &buffer_size);
316 // align the size to CodeEntryAlignment
317 size = CodeBlob::align_code_offset(size);
318 size += round_to(buffer_size, oopSize);
319 {
320 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
321 blob = new (size) MethodHandlesAdapterBlob(size);
322 if (blob == NULL) {
323 vm_exit_out_of_memory(size, OOM_MALLOC_ERROR, "CodeCache: no room for method handle adapter blob");
324 }
325 }
326 // Track memory usage statistic after releasing CodeCache_lock
327 MemoryService::track_code_cache_memory_usage();
328
329 return blob;
330 }
331
332 //----------------------------------------------------------------------------------------------------
333 // Implementation of RuntimeStub
334
335 RuntimeStub::RuntimeStub(
337 CodeBuffer* cb,
338 int size,
339 int frame_complete,
340 int frame_size,
341 OopMapSet* oop_maps,
342 bool caller_must_gc_arguments
343 )
344 : RuntimeBlob(name, cb, sizeof(RuntimeStub), size, frame_complete, frame_size, oop_maps, caller_must_gc_arguments)
345 {
346 }
347
348 RuntimeStub* RuntimeStub::new_runtime_stub(const char* stub_name,
349 CodeBuffer* cb,
350 int frame_complete,
351 int frame_size,
352 OopMapSet* oop_maps,
353 bool caller_must_gc_arguments)
354 {
355 RuntimeStub* stub = NULL;
356 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
357 if (!CodeCacheExtensions::skip_code_generation()) {
358 // bypass useless code generation
359 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
360 unsigned int size = CodeBlob::allocation_size(cb, sizeof(RuntimeStub));
361 stub = new (size) RuntimeStub(stub_name, cb, size, frame_complete, frame_size, oop_maps, caller_must_gc_arguments);
362 }
363 stub = (RuntimeStub*) CodeCacheExtensions::handle_generated_blob(stub, stub_name);
364
365 trace_new_stub(stub, "RuntimeStub - ", stub_name);
366
367 return stub;
368 }
369
370
371 void* RuntimeStub::operator new(size_t s, unsigned size) throw() {
372 void* p = CodeCache::allocate(size, CodeBlobType::NonNMethod);
373 if (!p) fatal("Initial size of CodeCache is too small");
374 return p;
375 }
376
377 // operator new shared by all singletons:
378 void* SingletonBlob::operator new(size_t s, unsigned size) throw() {
379 void* p = CodeCache::allocate(size, CodeBlobType::NonNMethod);
380 if (!p) fatal("Initial size of CodeCache is too small");
381 return p;
382 }
383
|
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "code/codeBlob.hpp"
27 #include "code/codeCache.hpp"
28 #include "code/relocInfo.hpp"
29 #include "compiler/disassembler.hpp"
30 #include "interpreter/bytecode.hpp"
31 #include "memory/allocation.inline.hpp"
32 #include "memory/heap.hpp"
33 #include "memory/resourceArea.hpp"
34 #include "oops/oop.inline.hpp"
35 #include "prims/forte.hpp"
36 #include "runtime/handles.inline.hpp"
37 #include "runtime/interfaceSupport.hpp"
38 #include "runtime/mutexLocker.hpp"
39 #include "runtime/safepoint.hpp"
40 #include "runtime/sharedRuntime.hpp"
41 #include "runtime/vframe.hpp"
42 #include "services/memoryService.hpp"
43 #ifdef COMPILER1
44 #include "c1/c1_Runtime1.hpp"
45 #endif
46
47 const char* CodeBlob::compiler_name() const {
210
211 void CodeBlob::print_code() {
212 HandleMark hm;
213 ResourceMark m;
214 Disassembler::decode(this, tty);
215 }
216
217 //----------------------------------------------------------------------------------------------------
218 // Implementation of BufferBlob
219
220
221 BufferBlob::BufferBlob(const char* name, int size)
222 : RuntimeBlob(name, sizeof(BufferBlob), size, CodeOffsets::frame_never_safe, /*locs_size:*/ 0)
223 {}
224
225 BufferBlob* BufferBlob::create(const char* name, int buffer_size) {
226 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
227
228 BufferBlob* blob = NULL;
229 unsigned int size = sizeof(BufferBlob);
230 // align the size to CodeEntryAlignment
231 size = CodeBlob::align_code_offset(size);
232 size += round_to(buffer_size, oopSize);
233 assert(name != NULL, "must provide a name");
234 {
235 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
236 blob = new (size) BufferBlob(name, size);
237 }
238 // Track memory usage statistic after releasing CodeCache_lock
239 MemoryService::track_code_cache_memory_usage();
240
241 return blob;
242 }
243
244
245 BufferBlob::BufferBlob(const char* name, int size, CodeBuffer* cb)
246 : RuntimeBlob(name, cb, sizeof(BufferBlob), size, CodeOffsets::frame_never_safe, 0, NULL)
247 {}
248
249 BufferBlob* BufferBlob::create(const char* name, CodeBuffer* cb) {
293 unsigned int size = CodeBlob::allocation_size(cb, sizeof(AdapterBlob));
294 {
295 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
296 blob = new (size) AdapterBlob(size, cb);
297 }
298 // Track memory usage statistic after releasing CodeCache_lock
299 MemoryService::track_code_cache_memory_usage();
300
301 return blob;
302 }
303
304
305 //----------------------------------------------------------------------------------------------------
306 // Implementation of MethodHandlesAdapterBlob
307
308 MethodHandlesAdapterBlob* MethodHandlesAdapterBlob::create(int buffer_size) {
309 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
310
311 MethodHandlesAdapterBlob* blob = NULL;
312 unsigned int size = sizeof(MethodHandlesAdapterBlob);
313 // align the size to CodeEntryAlignment
314 size = CodeBlob::align_code_offset(size);
315 size += round_to(buffer_size, oopSize);
316 {
317 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
318 blob = new (size) MethodHandlesAdapterBlob(size);
319 if (blob == NULL) {
320 vm_exit_out_of_memory(size, OOM_MALLOC_ERROR, "CodeCache: no room for method handle adapter blob");
321 }
322 }
323 // Track memory usage statistic after releasing CodeCache_lock
324 MemoryService::track_code_cache_memory_usage();
325
326 return blob;
327 }
328
329 //----------------------------------------------------------------------------------------------------
330 // Implementation of RuntimeStub
331
332 RuntimeStub::RuntimeStub(
334 CodeBuffer* cb,
335 int size,
336 int frame_complete,
337 int frame_size,
338 OopMapSet* oop_maps,
339 bool caller_must_gc_arguments
340 )
341 : RuntimeBlob(name, cb, sizeof(RuntimeStub), size, frame_complete, frame_size, oop_maps, caller_must_gc_arguments)
342 {
343 }
344
345 RuntimeStub* RuntimeStub::new_runtime_stub(const char* stub_name,
346 CodeBuffer* cb,
347 int frame_complete,
348 int frame_size,
349 OopMapSet* oop_maps,
350 bool caller_must_gc_arguments)
351 {
352 RuntimeStub* stub = NULL;
353 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
354 {
355 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
356 unsigned int size = CodeBlob::allocation_size(cb, sizeof(RuntimeStub));
357 stub = new (size) RuntimeStub(stub_name, cb, size, frame_complete, frame_size, oop_maps, caller_must_gc_arguments);
358 }
359
360 trace_new_stub(stub, "RuntimeStub - ", stub_name);
361
362 return stub;
363 }
364
365
366 void* RuntimeStub::operator new(size_t s, unsigned size) throw() {
367 void* p = CodeCache::allocate(size, CodeBlobType::NonNMethod);
368 if (!p) fatal("Initial size of CodeCache is too small");
369 return p;
370 }
371
372 // operator new shared by all singletons:
373 void* SingletonBlob::operator new(size_t s, unsigned size) throw() {
374 void* p = CodeCache::allocate(size, CodeBlobType::NonNMethod);
375 if (!p) fatal("Initial size of CodeCache is too small");
376 return p;
377 }
378
|