src/share/vm/code/codeCache.cpp

Print this page
rev 4773 : 8005849: JEP 167: Event-Based JVM Tracing
Reviewed-by: acorn, coleenp, sla
Contributed-by: Karen Kinnear <karen.kinnear@oracle.com>, Bengt Rutisson <bengt.rutisson@oracle.com>, Calvin Cheung <calvin.cheung@oracle.com>, Erik Gahlin <erik.gahlin@oracle.com>, Erik Helin <erik.helin@oracle.com>, Jesper Wilhelmsson <jesper.wilhelmsson@oracle.com>, Keith McGuigan <keith.mcguigan@oracle.com>, Mattias Tobiasson <mattias.tobiasson@oracle.com>, Markus Gronlund <markus.gronlund@oracle.com>, Mikael Auno <mikael.auno@oracle.com>, Nils Eliasson <nils.eliasson@oracle.com>, Nils Loodin <nils.loodin@oracle.com>, Rickard Backman <rickard.backman@oracle.com>, Staffan Larsen <staffan.larsen@oracle.com>, Stefan Karlsson <stefan.karlsson@oracle.com>, Yekaterina Kantserova <yekaterina.kantserova@oracle.com>
   1 /*
   2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   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  *


  28 #include "code/compiledIC.hpp"
  29 #include "code/dependencies.hpp"
  30 #include "code/icBuffer.hpp"
  31 #include "code/nmethod.hpp"
  32 #include "code/pcDesc.hpp"
  33 #include "compiler/compileBroker.hpp"
  34 #include "gc_implementation/shared/markSweep.hpp"
  35 #include "memory/allocation.inline.hpp"
  36 #include "memory/gcLocker.hpp"
  37 #include "memory/iterator.hpp"
  38 #include "memory/resourceArea.hpp"
  39 #include "oops/method.hpp"
  40 #include "oops/objArrayOop.hpp"
  41 #include "oops/oop.inline.hpp"
  42 #include "runtime/handles.inline.hpp"
  43 #include "runtime/arguments.hpp"
  44 #include "runtime/icache.hpp"
  45 #include "runtime/java.hpp"
  46 #include "runtime/mutexLocker.hpp"
  47 #include "services/memoryService.hpp"

  48 #include "utilities/xmlstream.hpp"
  49 
  50 // Helper class for printing in CodeCache
  51 
  52 class CodeBlob_sizes {
  53  private:
  54   int count;
  55   int total_size;
  56   int header_size;
  57   int code_size;
  58   int stub_size;
  59   int relocation_size;
  60   int scopes_oop_size;
  61   int scopes_metadata_size;
  62   int scopes_data_size;
  63   int scopes_pcs_size;
  64 
  65  public:
  66   CodeBlob_sizes() {
  67     count            = 0;


  97   void add(CodeBlob* cb) {
  98     count++;
  99     total_size       += cb->size();
 100     header_size      += cb->header_size();
 101     relocation_size  += cb->relocation_size();
 102     if (cb->is_nmethod()) {
 103       nmethod* nm = cb->as_nmethod_or_null();
 104       code_size        += nm->insts_size();
 105       stub_size        += nm->stub_size();
 106 
 107       scopes_oop_size  += nm->oops_size();
 108       scopes_metadata_size  += nm->metadata_size();
 109       scopes_data_size += nm->scopes_data_size();
 110       scopes_pcs_size  += nm->scopes_pcs_size();
 111     } else {
 112       code_size        += cb->code_size();
 113     }
 114   }
 115 };
 116 
 117 
 118 // CodeCache implementation
 119 
 120 CodeHeap * CodeCache::_heap = new CodeHeap();
 121 int CodeCache::_number_of_blobs = 0;
 122 int CodeCache::_number_of_adapters = 0;
 123 int CodeCache::_number_of_nmethods = 0;
 124 int CodeCache::_number_of_nmethods_with_dependencies = 0;
 125 bool CodeCache::_needs_cache_clean = false;
 126 nmethod* CodeCache::_scavenge_root_nmethods = NULL;
 127 nmethod* CodeCache::_saved_nmethods = NULL;
 128 

 129 
 130 CodeBlob* CodeCache::first() {
 131   assert_locked_or_safepoint(CodeCache_lock);
 132   return (CodeBlob*)_heap->first();
 133 }
 134 
 135 
 136 CodeBlob* CodeCache::next(CodeBlob* cb) {
 137   assert_locked_or_safepoint(CodeCache_lock);
 138   return (CodeBlob*)_heap->next(cb);
 139 }
 140 
 141 
 142 CodeBlob* CodeCache::alive(CodeBlob *cb) {
 143   assert_locked_or_safepoint(CodeCache_lock);
 144   while (cb != NULL && !cb->is_alive()) cb = next(cb);
 145   return cb;
 146 }
 147 
 148 


 812     }
 813   }
 814 }
 815 
 816 void CodeCache::make_marked_nmethods_not_entrant() {
 817   assert_locked_or_safepoint(CodeCache_lock);
 818   FOR_ALL_ALIVE_NMETHODS(nm) {
 819     if (nm->is_marked_for_deoptimization()) {
 820       nm->make_not_entrant();
 821     }
 822   }
 823 }
 824 
 825 void CodeCache::verify() {
 826   _heap->verify();
 827   FOR_ALL_ALIVE_BLOBS(p) {
 828     p->verify();
 829   }
 830 }
 831 
















 832 //------------------------------------------------------------------------------------------------
 833 // Non-product version
 834 
 835 #ifndef PRODUCT
 836 
 837 void CodeCache::verify_if_often() {
 838   if (VerifyCodeCacheOften) {
 839     _heap->verify();
 840   }
 841 }
 842 
 843 void CodeCache::print_trace(const char* event, CodeBlob* cb, int size) {
 844   if (PrintCodeCache2) {  // Need to add a new flag
 845     ResourceMark rm;
 846     if (size == 0)  size = cb->size();
 847     tty->print_cr("CodeCache %s:  addr: " INTPTR_FORMAT ", size: 0x%x", event, cb, size);
 848   }
 849 }
 850 
 851 void CodeCache::print_internals() {


   1 /*
   2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   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  *


  28 #include "code/compiledIC.hpp"
  29 #include "code/dependencies.hpp"
  30 #include "code/icBuffer.hpp"
  31 #include "code/nmethod.hpp"
  32 #include "code/pcDesc.hpp"
  33 #include "compiler/compileBroker.hpp"
  34 #include "gc_implementation/shared/markSweep.hpp"
  35 #include "memory/allocation.inline.hpp"
  36 #include "memory/gcLocker.hpp"
  37 #include "memory/iterator.hpp"
  38 #include "memory/resourceArea.hpp"
  39 #include "oops/method.hpp"
  40 #include "oops/objArrayOop.hpp"
  41 #include "oops/oop.inline.hpp"
  42 #include "runtime/handles.inline.hpp"
  43 #include "runtime/arguments.hpp"
  44 #include "runtime/icache.hpp"
  45 #include "runtime/java.hpp"
  46 #include "runtime/mutexLocker.hpp"
  47 #include "services/memoryService.hpp"
  48 #include "trace/tracing.hpp"
  49 #include "utilities/xmlstream.hpp"
  50 
  51 // Helper class for printing in CodeCache
  52 
  53 class CodeBlob_sizes {
  54  private:
  55   int count;
  56   int total_size;
  57   int header_size;
  58   int code_size;
  59   int stub_size;
  60   int relocation_size;
  61   int scopes_oop_size;
  62   int scopes_metadata_size;
  63   int scopes_data_size;
  64   int scopes_pcs_size;
  65 
  66  public:
  67   CodeBlob_sizes() {
  68     count            = 0;


  98   void add(CodeBlob* cb) {
  99     count++;
 100     total_size       += cb->size();
 101     header_size      += cb->header_size();
 102     relocation_size  += cb->relocation_size();
 103     if (cb->is_nmethod()) {
 104       nmethod* nm = cb->as_nmethod_or_null();
 105       code_size        += nm->insts_size();
 106       stub_size        += nm->stub_size();
 107 
 108       scopes_oop_size  += nm->oops_size();
 109       scopes_metadata_size  += nm->metadata_size();
 110       scopes_data_size += nm->scopes_data_size();
 111       scopes_pcs_size  += nm->scopes_pcs_size();
 112     } else {
 113       code_size        += cb->code_size();
 114     }
 115   }
 116 };
 117 

 118 // CodeCache implementation
 119 
 120 CodeHeap * CodeCache::_heap = new CodeHeap();
 121 int CodeCache::_number_of_blobs = 0;
 122 int CodeCache::_number_of_adapters = 0;
 123 int CodeCache::_number_of_nmethods = 0;
 124 int CodeCache::_number_of_nmethods_with_dependencies = 0;
 125 bool CodeCache::_needs_cache_clean = false;
 126 nmethod* CodeCache::_scavenge_root_nmethods = NULL;
 127 nmethod* CodeCache::_saved_nmethods = NULL;
 128 
 129 int CodeCache::_codemem_full_count = 0;
 130 
 131 CodeBlob* CodeCache::first() {
 132   assert_locked_or_safepoint(CodeCache_lock);
 133   return (CodeBlob*)_heap->first();
 134 }
 135 
 136 
 137 CodeBlob* CodeCache::next(CodeBlob* cb) {
 138   assert_locked_or_safepoint(CodeCache_lock);
 139   return (CodeBlob*)_heap->next(cb);
 140 }
 141 
 142 
 143 CodeBlob* CodeCache::alive(CodeBlob *cb) {
 144   assert_locked_or_safepoint(CodeCache_lock);
 145   while (cb != NULL && !cb->is_alive()) cb = next(cb);
 146   return cb;
 147 }
 148 
 149 


 813     }
 814   }
 815 }
 816 
 817 void CodeCache::make_marked_nmethods_not_entrant() {
 818   assert_locked_or_safepoint(CodeCache_lock);
 819   FOR_ALL_ALIVE_NMETHODS(nm) {
 820     if (nm->is_marked_for_deoptimization()) {
 821       nm->make_not_entrant();
 822     }
 823   }
 824 }
 825 
 826 void CodeCache::verify() {
 827   _heap->verify();
 828   FOR_ALL_ALIVE_BLOBS(p) {
 829     p->verify();
 830   }
 831 }
 832 
 833 void CodeCache::report_codemem_full() {
 834   _codemem_full_count++;
 835   EventCodeCacheFull event;
 836   if (event.should_commit()) {
 837     event.set_startAddress((u8)low_bound());
 838     event.set_commitedTopAddress((u8)high());
 839     event.set_reservedTopAddress((u8)high_bound());
 840     event.set_entryCount(nof_blobs());
 841     event.set_methodCount(nof_nmethods());
 842     event.set_adaptorCount(nof_adapters());
 843     event.set_unallocatedCapacity(unallocated_capacity()/K);
 844     event.set_fullCount(_codemem_full_count);
 845     event.commit();
 846   }
 847 }
 848 
 849 //------------------------------------------------------------------------------------------------
 850 // Non-product version
 851 
 852 #ifndef PRODUCT
 853 
 854 void CodeCache::verify_if_often() {
 855   if (VerifyCodeCacheOften) {
 856     _heap->verify();
 857   }
 858 }
 859 
 860 void CodeCache::print_trace(const char* event, CodeBlob* cb, int size) {
 861   if (PrintCodeCache2) {  // Need to add a new flag
 862     ResourceMark rm;
 863     if (size == 0)  size = cb->size();
 864     tty->print_cr("CodeCache %s:  addr: " INTPTR_FORMAT ", size: 0x%x", event, cb, size);
 865   }
 866 }
 867 
 868 void CodeCache::print_internals() {