src/share/vm/gc_implementation/g1/g1CodeCacheRemSet.hpp

Mon, 07 Jul 2014 10:12:40 +0200

author
stefank
date
Mon, 07 Jul 2014 10:12:40 +0200
changeset 6992
2c6ef90f030a
parent 6932
828056cf311f
child 7208
7baf47cb97cb
permissions
-rw-r--r--

8049421: G1 Class Unloading after completing a concurrent mark cycle
Reviewed-by: tschatzl, ehelin, brutisso, coleenp, roland, iveresov
Contributed-by: stefan.karlsson@oracle.com, mikael.gerdin@oracle.com

     1 /*
     2  * Copyright (c) 2014, 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  *
    23  */
    25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1CODECACHEREMSET_HPP
    26 #define SHARE_VM_GC_IMPLEMENTATION_G1_G1CODECACHEREMSET_HPP
    28 #include "memory/allocation.hpp"
    29 #include "memory/freeList.hpp"
    30 #include "runtime/globals.hpp"
    32 class CodeBlobClosure;
    34 // The elements of the G1CodeRootChunk is either:
    35 //  1) nmethod pointers
    36 //  2) nodes in an internally chained free list
    37 typedef union {
    38   nmethod* _nmethod;
    39   void*    _link;
    40 } NmethodOrLink;
    42 class G1CodeRootChunk : public CHeapObj<mtGC> {
    43  private:
    44   static const int NUM_ENTRIES = 32;
    45  public:
    46   G1CodeRootChunk*     _next;
    47   G1CodeRootChunk*     _prev;
    49   NmethodOrLink*          _top;
    50   // First free position within the chunk.
    51   volatile NmethodOrLink* _free;
    53   NmethodOrLink _data[NUM_ENTRIES];
    55   NmethodOrLink* bottom() const {
    56     return (NmethodOrLink*) &(_data[0]);
    57   }
    59   NmethodOrLink* end() const {
    60     return (NmethodOrLink*) &(_data[NUM_ENTRIES]);
    61   }
    63   bool is_link(NmethodOrLink* nmethod_or_link) {
    64     return nmethod_or_link->_link == NULL ||
    65         (bottom() <= nmethod_or_link->_link
    66         && nmethod_or_link->_link < end());
    67   }
    69   bool is_nmethod(NmethodOrLink* nmethod_or_link) {
    70     return !is_link(nmethod_or_link);
    71   }
    73  public:
    74   G1CodeRootChunk();
    75   ~G1CodeRootChunk() {}
    77   static size_t word_size() { return (size_t)(align_size_up_(sizeof(G1CodeRootChunk), HeapWordSize) / HeapWordSize); }
    79   // FreeList "interface" methods
    81   G1CodeRootChunk* next() const         { return _next; }
    82   G1CodeRootChunk* prev() const         { return _prev; }
    83   void set_next(G1CodeRootChunk* v)     { _next = v; assert(v != this, "Boom");}
    84   void set_prev(G1CodeRootChunk* v)     { _prev = v; assert(v != this, "Boom");}
    85   void clear_next()       { set_next(NULL); }
    86   void clear_prev()       { set_prev(NULL); }
    88   size_t size() const { return word_size(); }
    90   void link_next(G1CodeRootChunk* ptr)  { set_next(ptr); }
    91   void link_prev(G1CodeRootChunk* ptr)  { set_prev(ptr); }
    92   void link_after(G1CodeRootChunk* ptr) {
    93     link_next(ptr);
    94     if (ptr != NULL) ptr->link_prev((G1CodeRootChunk*)this);
    95   }
    97   bool is_free()                 { return true; }
    99   // New G1CodeRootChunk routines
   101   void reset();
   103   bool is_empty() const {
   104     return _top == bottom();
   105   }
   107   bool is_full() const {
   108     return _top == end() && _free == NULL;
   109   }
   111   bool contains(nmethod* method) {
   112     NmethodOrLink* cur = bottom();
   113     while (cur != _top) {
   114       if (cur->_nmethod == method) return true;
   115       cur++;
   116     }
   117     return false;
   118   }
   120   bool add(nmethod* method) {
   121     if (is_full()) {
   122       return false;
   123     }
   125     if (_free != NULL) {
   126       // Take from internally chained free list
   127       NmethodOrLink* first_free = (NmethodOrLink*)_free;
   128       _free = (NmethodOrLink*)_free->_link;
   129       first_free->_nmethod = method;
   130     } else {
   131       // Take from top.
   132       _top->_nmethod = method;
   133       _top++;
   134     }
   136     return true;
   137   }
   139   bool remove_lock_free(nmethod* method);
   141   void nmethods_do(CodeBlobClosure* blk);
   143   nmethod* pop() {
   144     if (_free != NULL) {
   145       // Kill the free list.
   146       _free = NULL;
   147     }
   149     while (!is_empty()) {
   150       _top--;
   151       if (is_nmethod(_top)) {
   152         return _top->_nmethod;
   153       }
   154     }
   156     return NULL;
   157   }
   158 };
   160 // Manages free chunks.
   161 class G1CodeRootChunkManager VALUE_OBJ_CLASS_SPEC {
   162  private:
   163   // Global free chunk list management
   164   FreeList<G1CodeRootChunk> _free_list;
   165   // Total number of chunks handed out
   166   size_t _num_chunks_handed_out;
   168  public:
   169   G1CodeRootChunkManager();
   171   G1CodeRootChunk* new_chunk();
   172   void free_chunk(G1CodeRootChunk* chunk);
   173   // Free all elements of the given list.
   174   void free_all_chunks(FreeList<G1CodeRootChunk>* list);
   176   void initialize();
   177   void purge_chunks(size_t keep_ratio);
   179   static size_t static_mem_size();
   180   size_t fl_mem_size();
   182 #ifndef PRODUCT
   183   size_t num_chunks_handed_out() const;
   184   size_t num_free_chunks() const;
   185 #endif
   186 };
   188 // Implements storage for a set of code roots.
   189 // All methods that modify the set are not thread-safe except if otherwise noted.
   190 class G1CodeRootSet VALUE_OBJ_CLASS_SPEC {
   191  private:
   192   // Global default free chunk manager instance.
   193   static G1CodeRootChunkManager _default_chunk_manager;
   195   G1CodeRootChunk* new_chunk() { return _manager->new_chunk(); }
   196   void free_chunk(G1CodeRootChunk* chunk) { _manager->free_chunk(chunk); }
   197   // Free all elements of the given list.
   198   void free_all_chunks(FreeList<G1CodeRootChunk>* list) { _manager->free_all_chunks(list); }
   200   // Return the chunk that contains the given nmethod, NULL otherwise.
   201   // Scans the list of chunks backwards, as this method is used to add new
   202   // entries, which are typically added in bulk for a single nmethod.
   203   G1CodeRootChunk* find(nmethod* method);
   204   void free(G1CodeRootChunk* chunk);
   206   size_t _length;
   207   FreeList<G1CodeRootChunk> _list;
   208   G1CodeRootChunkManager* _manager;
   210  public:
   211   // If an instance is initialized with a chunk manager of NULL, use the global
   212   // default one.
   213   G1CodeRootSet(G1CodeRootChunkManager* manager = NULL);
   214   ~G1CodeRootSet();
   216   static void purge_chunks(size_t keep_ratio);
   218   static size_t free_chunks_static_mem_size();
   219   static size_t free_chunks_mem_size();
   221   // Search for the code blob from the recently allocated ones to find duplicates more quickly, as this
   222   // method is likely to be repeatedly called with the same nmethod.
   223   void add(nmethod* method);
   225   void remove_lock_free(nmethod* method);
   226   nmethod* pop();
   228   bool contains(nmethod* method);
   230   void clear();
   232   void nmethods_do(CodeBlobClosure* blk) const;
   234   bool is_empty() { return length() == 0; }
   236   // Length in elements
   237   size_t length() const { return _length; }
   239   // Static data memory size in bytes of this set.
   240   static size_t static_mem_size();
   241   // Memory size in bytes taken by this set.
   242   size_t mem_size();
   244   static void test() PRODUCT_RETURN;
   245 };
   247 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1CODECACHEREMSET_HPP

mercurial