342 return !gch->is_in_young(p);
343 WB_END
344
345 WB_ENTRY(jlong, WB_GetObjectSize(JNIEnv* env, jobject o, jobject obj))
346 oop p = JNIHandles::resolve(obj);
347 return p->size() * HeapWordSize;
348 WB_END
349
350 WB_ENTRY(jlong, WB_GetHeapSpaceAlignment(JNIEnv* env, jobject o))
351 size_t alignment = Universe::heap()->collector_policy()->space_alignment();
352 return (jlong)alignment;
353 WB_END
354
355 WB_ENTRY(jlong, WB_GetHeapAlignment(JNIEnv* env, jobject o))
356 size_t alignment = Universe::heap()->collector_policy()->heap_alignment();
357 return (jlong)alignment;
358 WB_END
359
360 #if INCLUDE_ALL_GCS
361 WB_ENTRY(jboolean, WB_G1IsHumongous(JNIEnv* env, jobject o, jobject obj))
362 G1CollectedHeap* g1 = G1CollectedHeap::heap();
363 oop result = JNIHandles::resolve(obj);
364 const HeapRegion* hr = g1->heap_region_containing(result);
365 return hr->is_humongous();
366 WB_END
367
368 WB_ENTRY(jboolean, WB_G1BelongsToHumongousRegion(JNIEnv* env, jobject o, jlong addr))
369 G1CollectedHeap* g1 = G1CollectedHeap::heap();
370 const HeapRegion* hr = g1->heap_region_containing((void*) addr);
371 return hr->is_humongous();
372 WB_END
373
374 WB_ENTRY(jboolean, WB_G1BelongsToFreeRegion(JNIEnv* env, jobject o, jlong addr))
375 G1CollectedHeap* g1 = G1CollectedHeap::heap();
376 const HeapRegion* hr = g1->heap_region_containing((void*) addr);
377 return hr->is_free();
378 WB_END
379
380 WB_ENTRY(jlong, WB_G1NumMaxRegions(JNIEnv* env, jobject o))
381 G1CollectedHeap* g1 = G1CollectedHeap::heap();
382 size_t nr = g1->max_regions();
383 return (jlong)nr;
384 WB_END
385
386 WB_ENTRY(jlong, WB_G1NumFreeRegions(JNIEnv* env, jobject o))
387 G1CollectedHeap* g1 = G1CollectedHeap::heap();
388 size_t nr = g1->num_free_regions();
389 return (jlong)nr;
390 WB_END
391
392 WB_ENTRY(jboolean, WB_G1InConcurrentMark(JNIEnv* env, jobject o))
393 G1CollectedHeap* g1h = G1CollectedHeap::heap();
394 return g1h->concurrent_mark()->cmThread()->during_cycle();
395 WB_END
396
397 WB_ENTRY(jboolean, WB_G1StartMarkCycle(JNIEnv* env, jobject o))
398 G1CollectedHeap* g1h = G1CollectedHeap::heap();
399 if (!g1h->concurrent_mark()->cmThread()->during_cycle()) {
400 g1h->collect(GCCause::_wb_conc_mark);
401 return true;
402 }
403 return false;
404 WB_END
405
406 WB_ENTRY(jint, WB_G1RegionSize(JNIEnv* env, jobject o))
407 return (jint)HeapRegion::GrainBytes;
408 WB_END
409
410 WB_ENTRY(jlong, WB_PSVirtualSpaceAlignment(JNIEnv* env, jobject o))
411 #if INCLUDE_ALL_GCS
412 if (UseParallelGC) {
413 return ParallelScavengeHeap::heap()->gens()->virtual_spaces()->alignment();
414 }
415 #endif // INCLUDE_ALL_GCS
416 THROW_MSG_0(vmSymbols::java_lang_RuntimeException(), "WB_PSVirtualSpaceAlignment: Parallel GC is not enabled");
417 WB_END
418
419 WB_ENTRY(jlong, WB_PSHeapGenerationAlignment(JNIEnv* env, jobject o))
420 #if INCLUDE_ALL_GCS
421 if (UseParallelGC) {
422 return ParallelScavengeHeap::heap()->generation_alignment();
423 }
424 #endif // INCLUDE_ALL_GCS
425 THROW_MSG_0(vmSymbols::java_lang_RuntimeException(), "WB_PSHeapGenerationAlignment: Parallel GC is not enabled");
426 WB_END
427
428 WB_ENTRY(jobject, WB_G1AuxiliaryMemoryUsage(JNIEnv* env))
429 ResourceMark rm(THREAD);
430 G1CollectedHeap* g1h = G1CollectedHeap::heap();
431 MemoryUsage usage = g1h->get_auxiliary_data_memory_usage();
432 Handle h = MemoryService::create_MemoryUsage_obj(usage, CHECK_NULL);
433 return JNIHandles::make_local(env, h());
434 WB_END
435
436 class OldRegionsLivenessClosure: public HeapRegionClosure {
437
438 private:
439 const int _liveness;
440 size_t _total_count;
441 size_t _total_memory;
442 size_t _total_memory_to_free;
443
444 public:
445 OldRegionsLivenessClosure(int liveness) :
446 _liveness(liveness),
447 _total_count(0),
448 _total_memory(0),
449 _total_memory_to_free(0) { }
450
451 size_t total_count() { return _total_count; }
452 size_t total_memory() { return _total_memory; }
453 size_t total_memory_to_free() { return _total_memory_to_free; }
458 size_t live = r->live_bytes();
459 size_t size = r->used();
460 size_t reg_size = HeapRegion::GrainBytes;
461 if (size > 0 && ((int)(live * 100 / size) < _liveness)) {
462 _total_memory += size;
463 ++_total_count;
464 if (size == reg_size) {
465 // we don't include non-full regions since they are unlikely included in mixed gc
466 // for testing purposes it's enough to have lowest estimation of total memory that is expected to be freed
467 _total_memory_to_free += size - prev_live;
468 }
469 }
470 }
471 return false;
472 }
473 };
474
475
476 WB_ENTRY(jlongArray, WB_G1GetMixedGCInfo(JNIEnv* env, jobject o, jint liveness))
477 if (!UseG1GC) {
478 THROW_MSG_NULL(vmSymbols::java_lang_RuntimeException(), "WB_G1GetMixedGCInfo: G1 is not enabled");
479 }
480 if (liveness < 0) {
481 THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "liveness value should be non-negative");
482 }
483
484 G1CollectedHeap* g1h = G1CollectedHeap::heap();
485 OldRegionsLivenessClosure rli(liveness);
486 g1h->heap_region_iterate(&rli);
487
488 typeArrayOop result = oopFactory::new_longArray(3, CHECK_NULL);
489 result->long_at_put(0, rli.total_count());
490 result->long_at_put(1, rli.total_memory());
491 result->long_at_put(2, rli.total_memory_to_free());
492 return (jlongArray) JNIHandles::make_local(env, result);
493 WB_END
494
495
496
497 #endif // INCLUDE_ALL_GCS
498
499 #if INCLUDE_NMT
500 // Alloc memory using the test memory type so that we can use that to see if
501 // NMT picks it up correctly
502 WB_ENTRY(jlong, WB_NMTMalloc(JNIEnv* env, jobject o, jlong size))
503 jlong addr = 0;
504 addr = (jlong)(uintptr_t)os::malloc(size, mtTest);
505 return addr;
506 WB_END
507
508 // Alloc memory with pseudo call stack. The test can create psudo malloc
509 // allocation site to stress the malloc tracking.
510 WB_ENTRY(jlong, WB_NMTMallocWithPseudoStack(JNIEnv* env, jobject o, jlong size, jint pseudo_stack))
511 address pc = (address)(size_t)pseudo_stack;
512 NativeCallStack stack(&pc, 1);
513 return (jlong)(uintptr_t)os::malloc(size, mtTest, stack);
514 WB_END
515
|
342 return !gch->is_in_young(p);
343 WB_END
344
345 WB_ENTRY(jlong, WB_GetObjectSize(JNIEnv* env, jobject o, jobject obj))
346 oop p = JNIHandles::resolve(obj);
347 return p->size() * HeapWordSize;
348 WB_END
349
350 WB_ENTRY(jlong, WB_GetHeapSpaceAlignment(JNIEnv* env, jobject o))
351 size_t alignment = Universe::heap()->collector_policy()->space_alignment();
352 return (jlong)alignment;
353 WB_END
354
355 WB_ENTRY(jlong, WB_GetHeapAlignment(JNIEnv* env, jobject o))
356 size_t alignment = Universe::heap()->collector_policy()->heap_alignment();
357 return (jlong)alignment;
358 WB_END
359
360 #if INCLUDE_ALL_GCS
361 WB_ENTRY(jboolean, WB_G1IsHumongous(JNIEnv* env, jobject o, jobject obj))
362 if (UseG1GC) {
363 G1CollectedHeap* g1 = G1CollectedHeap::heap();
364 oop result = JNIHandles::resolve(obj);
365 const HeapRegion* hr = g1->heap_region_containing(result);
366 return hr->is_humongous();
367 }
368 THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1IsHumongous: G1 GC is not enabled");
369 WB_END
370
371 WB_ENTRY(jboolean, WB_G1BelongsToHumongousRegion(JNIEnv* env, jobject o, jlong addr))
372 if (UseG1GC) {
373 G1CollectedHeap* g1 = G1CollectedHeap::heap();
374 const HeapRegion* hr = g1->heap_region_containing((void*) addr);
375 return hr->is_humongous();
376 }
377 THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1BelongsToHumongousRegion: G1 GC is not enabled");
378 WB_END
379
380 WB_ENTRY(jboolean, WB_G1BelongsToFreeRegion(JNIEnv* env, jobject o, jlong addr))
381 if (UseG1GC) {
382 G1CollectedHeap* g1 = G1CollectedHeap::heap();
383 const HeapRegion* hr = g1->heap_region_containing((void*) addr);
384 return hr->is_free();
385 }
386 THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1BelongsToFreeRegion: G1 GC is not enabled");
387 WB_END
388
389 WB_ENTRY(jlong, WB_G1NumMaxRegions(JNIEnv* env, jobject o))
390 if (UseG1GC) {
391 G1CollectedHeap* g1 = G1CollectedHeap::heap();
392 size_t nr = g1->max_regions();
393 return (jlong)nr;
394 }
395 THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1NumMaxRegions: G1 GC is not enabled");
396 WB_END
397
398 WB_ENTRY(jlong, WB_G1NumFreeRegions(JNIEnv* env, jobject o))
399 if (UseG1GC) {
400 G1CollectedHeap* g1 = G1CollectedHeap::heap();
401 size_t nr = g1->num_free_regions();
402 return (jlong)nr;
403 }
404 THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1NumFreeRegions: G1 GC is not enabled");
405 WB_END
406
407 WB_ENTRY(jboolean, WB_G1InConcurrentMark(JNIEnv* env, jobject o))
408 if (UseG1GC) {
409 G1CollectedHeap* g1h = G1CollectedHeap::heap();
410 return g1h->concurrent_mark()->cmThread()->during_cycle();
411 }
412 THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1InConcurrentMark: G1 GC is not enabled");
413 WB_END
414
415 WB_ENTRY(jboolean, WB_G1StartMarkCycle(JNIEnv* env, jobject o))
416 if (UseG1GC) {
417 G1CollectedHeap* g1h = G1CollectedHeap::heap();
418 if (!g1h->concurrent_mark()->cmThread()->during_cycle()) {
419 g1h->collect(GCCause::_wb_conc_mark);
420 return true;
421 }
422 return false;
423 }
424 THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1StartMarkCycle: G1 GC is not enabled");
425 WB_END
426
427 WB_ENTRY(jint, WB_G1RegionSize(JNIEnv* env, jobject o))
428 if (UseG1GC) {
429 return (jint)HeapRegion::GrainBytes;
430 }
431 THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1RegionSize: G1 GC is not enabled");
432 WB_END
433
434 WB_ENTRY(jlong, WB_PSVirtualSpaceAlignment(JNIEnv* env, jobject o))
435 #if INCLUDE_ALL_GCS
436 if (UseParallelGC) {
437 return ParallelScavengeHeap::heap()->gens()->virtual_spaces()->alignment();
438 }
439 #endif // INCLUDE_ALL_GCS
440 THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_PSVirtualSpaceAlignment: Parallel GC is not enabled");
441 WB_END
442
443 WB_ENTRY(jlong, WB_PSHeapGenerationAlignment(JNIEnv* env, jobject o))
444 #if INCLUDE_ALL_GCS
445 if (UseParallelGC) {
446 return ParallelScavengeHeap::heap()->generation_alignment();
447 }
448 #endif // INCLUDE_ALL_GCS
449 THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_PSHeapGenerationAlignment: Parallel GC is not enabled");
450 WB_END
451
452 WB_ENTRY(jobject, WB_G1AuxiliaryMemoryUsage(JNIEnv* env))
453 #if INCLUDE_ALL_GCS
454 if (UseG1GC) {
455 ResourceMark rm(THREAD);
456 G1CollectedHeap* g1h = G1CollectedHeap::heap();
457 MemoryUsage usage = g1h->get_auxiliary_data_memory_usage();
458 Handle h = MemoryService::create_MemoryUsage_obj(usage, CHECK_NULL);
459 return JNIHandles::make_local(env, h());
460 }
461 #endif // INCLUDE_ALL_GCS
462 THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1AuxiliaryMemoryUsage: G1 GC is not enabled");
463 WB_END
464
465 class OldRegionsLivenessClosure: public HeapRegionClosure {
466
467 private:
468 const int _liveness;
469 size_t _total_count;
470 size_t _total_memory;
471 size_t _total_memory_to_free;
472
473 public:
474 OldRegionsLivenessClosure(int liveness) :
475 _liveness(liveness),
476 _total_count(0),
477 _total_memory(0),
478 _total_memory_to_free(0) { }
479
480 size_t total_count() { return _total_count; }
481 size_t total_memory() { return _total_memory; }
482 size_t total_memory_to_free() { return _total_memory_to_free; }
487 size_t live = r->live_bytes();
488 size_t size = r->used();
489 size_t reg_size = HeapRegion::GrainBytes;
490 if (size > 0 && ((int)(live * 100 / size) < _liveness)) {
491 _total_memory += size;
492 ++_total_count;
493 if (size == reg_size) {
494 // we don't include non-full regions since they are unlikely included in mixed gc
495 // for testing purposes it's enough to have lowest estimation of total memory that is expected to be freed
496 _total_memory_to_free += size - prev_live;
497 }
498 }
499 }
500 return false;
501 }
502 };
503
504
505 WB_ENTRY(jlongArray, WB_G1GetMixedGCInfo(JNIEnv* env, jobject o, jint liveness))
506 if (!UseG1GC) {
507 THROW_MSG_NULL(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1GetMixedGCInfo: G1 GC is not enabled");
508 }
509 if (liveness < 0) {
510 THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "liveness value should be non-negative");
511 }
512
513 G1CollectedHeap* g1h = G1CollectedHeap::heap();
514 OldRegionsLivenessClosure rli(liveness);
515 g1h->heap_region_iterate(&rli);
516
517 typeArrayOop result = oopFactory::new_longArray(3, CHECK_NULL);
518 result->long_at_put(0, rli.total_count());
519 result->long_at_put(1, rli.total_memory());
520 result->long_at_put(2, rli.total_memory_to_free());
521 return (jlongArray) JNIHandles::make_local(env, result);
522 WB_END
523
524 #endif // INCLUDE_ALL_GCS
525
526 #if INCLUDE_NMT
527 // Alloc memory using the test memory type so that we can use that to see if
528 // NMT picks it up correctly
529 WB_ENTRY(jlong, WB_NMTMalloc(JNIEnv* env, jobject o, jlong size))
530 jlong addr = 0;
531 addr = (jlong)(uintptr_t)os::malloc(size, mtTest);
532 return addr;
533 WB_END
534
535 // Alloc memory with pseudo call stack. The test can create psudo malloc
536 // allocation site to stress the malloc tracking.
537 WB_ENTRY(jlong, WB_NMTMallocWithPseudoStack(JNIEnv* env, jobject o, jlong size, jint pseudo_stack))
538 address pc = (address)(size_t)pseudo_stack;
539 NativeCallStack stack(&pc, 1);
540 return (jlong)(uintptr_t)os::malloc(size, mtTest, stack);
541 WB_END
542
|