< prev index next >

src/share/vm/code/codeCache.cpp

Print this page




 348   assert_locked_or_safepoint(CodeCache_lock);
 349   assert(heap != NULL, "heap is null");
 350   return (CodeBlob*)heap->next(cb);
 351 }
 352 
 353 CodeBlob* CodeCache::next_blob(CodeBlob* cb) {
 354   return next_blob(get_code_heap(cb), cb);
 355 }
 356 
 357 /**
 358  * Do not seize the CodeCache lock here--if the caller has not
 359  * already done so, we are going to lose bigtime, since the code
 360  * cache will contain a garbage CodeBlob until the caller can
 361  * run the constructor for the CodeBlob subclass he is busy
 362  * instantiating.
 363  */
 364 CodeBlob* CodeCache::allocate(int size, int code_blob_type, bool strict) {
 365   // Possibly wakes up the sweeper thread.
 366   NMethodSweeper::notify(code_blob_type);
 367   assert_locked_or_safepoint(CodeCache_lock);
 368   assert(size > 0, err_msg_res("Code cache allocation request must be > 0 but is %d", size));
 369   if (size <= 0) {
 370     return NULL;
 371   }
 372   CodeBlob* cb = NULL;
 373 
 374   // Get CodeHeap for the given CodeBlobType
 375   CodeHeap* heap = get_code_heap(code_blob_type);
 376   assert(heap != NULL, "heap is null");
 377 
 378   while (true) {
 379     cb = (CodeBlob*)heap->allocate(size);
 380     if (cb != NULL) break;
 381     if (!heap->expand_by(CodeCacheExpansionSize)) {
 382       // Expansion failed
 383       if (SegmentedCodeCache && !strict) {
 384         // Fallback solution: Try to store code in another code heap.
 385         // Note that in the sweeper, we check the reverse_free_ratio of the code heap
 386         // and force stack scanning if less than 10% of the code heap are free.
 387         int type = code_blob_type;
 388         switch (type) {


 800   FOR_ALL_HEAPS(heap) {
 801     max_cap += (*heap)->max_capacity();
 802   }
 803   return max_cap;
 804 }
 805 
 806 /**
 807  * Returns the reverse free ratio. E.g., if 25% (1/4) of the code heap
 808  * is free, reverse_free_ratio() returns 4.
 809  */
 810 double CodeCache::reverse_free_ratio(int code_blob_type) {
 811   CodeHeap* heap = get_code_heap(code_blob_type);
 812   if (heap == NULL) {
 813     return 0;
 814   }
 815 
 816   double unallocated_capacity = MAX2((double)heap->unallocated_capacity(), 1.0); // Avoid division by 0;
 817   double max_capacity = (double)heap->max_capacity();
 818   double result = max_capacity / unallocated_capacity;
 819   assert (max_capacity >= unallocated_capacity, "Must be");
 820   assert (result >= 1.0, err_msg_res("reverse_free_ratio must be at least 1. It is %f", result));
 821   return result;
 822 }
 823 
 824 size_t CodeCache::bytes_allocated_in_freelists() {
 825   size_t allocated_bytes = 0;
 826   FOR_ALL_HEAPS(heap) {
 827     allocated_bytes += (*heap)->allocated_in_freelist();
 828   }
 829   return allocated_bytes;
 830 }
 831 
 832 int CodeCache::allocated_segments() {
 833   int number_of_segments = 0;
 834   FOR_ALL_HEAPS(heap) {
 835     number_of_segments += (*heap)->allocated_segments();
 836   }
 837   return number_of_segments;
 838 }
 839 
 840 size_t CodeCache::freelists_length() {




 348   assert_locked_or_safepoint(CodeCache_lock);
 349   assert(heap != NULL, "heap is null");
 350   return (CodeBlob*)heap->next(cb);
 351 }
 352 
 353 CodeBlob* CodeCache::next_blob(CodeBlob* cb) {
 354   return next_blob(get_code_heap(cb), cb);
 355 }
 356 
 357 /**
 358  * Do not seize the CodeCache lock here--if the caller has not
 359  * already done so, we are going to lose bigtime, since the code
 360  * cache will contain a garbage CodeBlob until the caller can
 361  * run the constructor for the CodeBlob subclass he is busy
 362  * instantiating.
 363  */
 364 CodeBlob* CodeCache::allocate(int size, int code_blob_type, bool strict) {
 365   // Possibly wakes up the sweeper thread.
 366   NMethodSweeper::notify(code_blob_type);
 367   assert_locked_or_safepoint(CodeCache_lock);
 368   assert(size > 0, "Code cache allocation request must be > 0 but is %d", size);
 369   if (size <= 0) {
 370     return NULL;
 371   }
 372   CodeBlob* cb = NULL;
 373 
 374   // Get CodeHeap for the given CodeBlobType
 375   CodeHeap* heap = get_code_heap(code_blob_type);
 376   assert(heap != NULL, "heap is null");
 377 
 378   while (true) {
 379     cb = (CodeBlob*)heap->allocate(size);
 380     if (cb != NULL) break;
 381     if (!heap->expand_by(CodeCacheExpansionSize)) {
 382       // Expansion failed
 383       if (SegmentedCodeCache && !strict) {
 384         // Fallback solution: Try to store code in another code heap.
 385         // Note that in the sweeper, we check the reverse_free_ratio of the code heap
 386         // and force stack scanning if less than 10% of the code heap are free.
 387         int type = code_blob_type;
 388         switch (type) {


 800   FOR_ALL_HEAPS(heap) {
 801     max_cap += (*heap)->max_capacity();
 802   }
 803   return max_cap;
 804 }
 805 
 806 /**
 807  * Returns the reverse free ratio. E.g., if 25% (1/4) of the code heap
 808  * is free, reverse_free_ratio() returns 4.
 809  */
 810 double CodeCache::reverse_free_ratio(int code_blob_type) {
 811   CodeHeap* heap = get_code_heap(code_blob_type);
 812   if (heap == NULL) {
 813     return 0;
 814   }
 815 
 816   double unallocated_capacity = MAX2((double)heap->unallocated_capacity(), 1.0); // Avoid division by 0;
 817   double max_capacity = (double)heap->max_capacity();
 818   double result = max_capacity / unallocated_capacity;
 819   assert (max_capacity >= unallocated_capacity, "Must be");
 820   assert (result >= 1.0, "reverse_free_ratio must be at least 1. It is %f", result);
 821   return result;
 822 }
 823 
 824 size_t CodeCache::bytes_allocated_in_freelists() {
 825   size_t allocated_bytes = 0;
 826   FOR_ALL_HEAPS(heap) {
 827     allocated_bytes += (*heap)->allocated_in_freelist();
 828   }
 829   return allocated_bytes;
 830 }
 831 
 832 int CodeCache::allocated_segments() {
 833   int number_of_segments = 0;
 834   FOR_ALL_HEAPS(heap) {
 835     number_of_segments += (*heap)->allocated_segments();
 836   }
 837   return number_of_segments;
 838 }
 839 
 840 size_t CodeCache::freelists_length() {


< prev index next >