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

changeset 0
f90c822e73f8
child 6925
82693fb204a5
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/gc_implementation/g1/g1CodeCacheRemSet.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,188 @@
     1.4 +/*
     1.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1CODECACHEREMSET_HPP
    1.29 +#define SHARE_VM_GC_IMPLEMENTATION_G1_G1CODECACHEREMSET_HPP
    1.30 +
    1.31 +#include "memory/allocation.hpp"
    1.32 +#include "memory/freeList.hpp"
    1.33 +#include "runtime/globals.hpp"
    1.34 +
    1.35 +class CodeBlobClosure;
    1.36 +
    1.37 +class G1CodeRootChunk : public CHeapObj<mtGC> {
    1.38 + private:
    1.39 +  static const int NUM_ENTRIES = 32;
    1.40 + public:
    1.41 +  G1CodeRootChunk*     _next;
    1.42 +  G1CodeRootChunk*     _prev;
    1.43 +
    1.44 +  nmethod** _top;
    1.45 +
    1.46 +  nmethod* _data[NUM_ENTRIES];
    1.47 +
    1.48 +  nmethod** bottom() const {
    1.49 +    return (nmethod**) &(_data[0]);
    1.50 +  }
    1.51 +
    1.52 +  nmethod** end() const {
    1.53 +    return (nmethod**) &(_data[NUM_ENTRIES]);
    1.54 +  }
    1.55 +
    1.56 + public:
    1.57 +  G1CodeRootChunk();
    1.58 +  ~G1CodeRootChunk() {}
    1.59 +
    1.60 +  static size_t word_size() { return (size_t)(align_size_up_(sizeof(G1CodeRootChunk), HeapWordSize) / HeapWordSize); }
    1.61 +
    1.62 +  // FreeList "interface" methods
    1.63 +
    1.64 +  G1CodeRootChunk* next() const         { return _next; }
    1.65 +  G1CodeRootChunk* prev() const         { return _prev; }
    1.66 +  void set_next(G1CodeRootChunk* v)     { _next = v; assert(v != this, "Boom");}
    1.67 +  void set_prev(G1CodeRootChunk* v)     { _prev = v; assert(v != this, "Boom");}
    1.68 +  void clear_next()       { set_next(NULL); }
    1.69 +  void clear_prev()       { set_prev(NULL); }
    1.70 +
    1.71 +  size_t size() const { return word_size(); }
    1.72 +
    1.73 +  void link_next(G1CodeRootChunk* ptr)  { set_next(ptr); }
    1.74 +  void link_prev(G1CodeRootChunk* ptr)  { set_prev(ptr); }
    1.75 +  void link_after(G1CodeRootChunk* ptr) {
    1.76 +    link_next(ptr);
    1.77 +    if (ptr != NULL) ptr->link_prev((G1CodeRootChunk*)this);
    1.78 +  }
    1.79 +
    1.80 +  bool is_free()                 { return true; }
    1.81 +
    1.82 +  // New G1CodeRootChunk routines
    1.83 +
    1.84 +  void reset();
    1.85 +
    1.86 +  bool is_empty() const {
    1.87 +    return _top == bottom();
    1.88 +  }
    1.89 +
    1.90 +  bool is_full() const {
    1.91 +    return _top == (nmethod**)end();
    1.92 +  }
    1.93 +
    1.94 +  bool contains(nmethod* method) {
    1.95 +    nmethod** cur = bottom();
    1.96 +    while (cur != _top) {
    1.97 +      if (*cur == method) return true;
    1.98 +      cur++;
    1.99 +    }
   1.100 +    return false;
   1.101 +  }
   1.102 +
   1.103 +  bool add(nmethod* method) {
   1.104 +    if (is_full()) return false;
   1.105 +    *_top = method;
   1.106 +    _top++;
   1.107 +    return true;
   1.108 +  }
   1.109 +
   1.110 +  bool remove(nmethod* method) {
   1.111 +    nmethod** cur = bottom();
   1.112 +    while (cur != _top) {
   1.113 +      if (*cur == method) {
   1.114 +        memmove(cur, cur + 1, (_top - (cur + 1)) * sizeof(nmethod**));
   1.115 +        _top--;
   1.116 +        return true;
   1.117 +      }
   1.118 +      cur++;
   1.119 +    }
   1.120 +    return false;
   1.121 +  }
   1.122 +
   1.123 +  void nmethods_do(CodeBlobClosure* blk);
   1.124 +
   1.125 +  nmethod* pop() {
   1.126 +    if (is_empty()) {
   1.127 +      return NULL;
   1.128 +    }
   1.129 +    _top--;
   1.130 +    return *_top;
   1.131 +  }
   1.132 +};
   1.133 +
   1.134 +// Implements storage for a set of code roots.
   1.135 +// All methods that modify the set are not thread-safe except if otherwise noted.
   1.136 +class G1CodeRootSet VALUE_OBJ_CLASS_SPEC {
   1.137 + private:
   1.138 +  // Global free chunk list management
   1.139 +  static FreeList<G1CodeRootChunk> _free_list;
   1.140 +  // Total number of chunks handed out
   1.141 +  static size_t _num_chunks_handed_out;
   1.142 +
   1.143 +  static G1CodeRootChunk* new_chunk();
   1.144 +  static void free_chunk(G1CodeRootChunk* chunk);
   1.145 +  // Free all elements of the given list.
   1.146 +  static void free_all_chunks(FreeList<G1CodeRootChunk>* list);
   1.147 +
   1.148 +  // Return the chunk that contains the given nmethod, NULL otherwise.
   1.149 +  // Scans the list of chunks backwards, as this method is used to add new
   1.150 +  // entries, which are typically added in bulk for a single nmethod.
   1.151 +  G1CodeRootChunk* find(nmethod* method);
   1.152 +  void free(G1CodeRootChunk* chunk);
   1.153 +
   1.154 +  size_t _length;
   1.155 +  FreeList<G1CodeRootChunk> _list;
   1.156 +
   1.157 + public:
   1.158 +  G1CodeRootSet();
   1.159 +  ~G1CodeRootSet();
   1.160 +
   1.161 +  static void initialize();
   1.162 +  static void purge_chunks(size_t keep_ratio);
   1.163 +
   1.164 +  static size_t static_mem_size();
   1.165 +  static size_t fl_mem_size();
   1.166 +
   1.167 +  // Search for the code blob from the recently allocated ones to find duplicates more quickly, as this
   1.168 +  // method is likely to be repeatedly called with the same nmethod.
   1.169 +  void add(nmethod* method);
   1.170 +
   1.171 +  void remove(nmethod* method);
   1.172 +  nmethod* pop();
   1.173 +
   1.174 +  bool contains(nmethod* method);
   1.175 +
   1.176 +  void clear();
   1.177 +
   1.178 +  void nmethods_do(CodeBlobClosure* blk) const;
   1.179 +
   1.180 +  bool is_empty() { return length() == 0; }
   1.181 +
   1.182 +  // Length in elements
   1.183 +  size_t length() const { return _length; }
   1.184 +
   1.185 +  // Memory size in bytes taken by this set.
   1.186 +  size_t mem_size();
   1.187 +
   1.188 +  static void test() PRODUCT_RETURN;
   1.189 +};
   1.190 +
   1.191 +#endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1CODECACHEREMSET_HPP

mercurial