aoqi@0: /* aoqi@0: * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1CODECACHEREMSET_HPP aoqi@0: #define SHARE_VM_GC_IMPLEMENTATION_G1_G1CODECACHEREMSET_HPP aoqi@0: aoqi@0: #include "memory/allocation.hpp" aoqi@0: aoqi@0: class CodeBlobClosure; mgerdin@7208: class CodeRootSetTable; mgerdin@7208: class HeapRegion; mgerdin@7208: class nmethod; tschatzl@6925: aoqi@0: // Implements storage for a set of code roots. aoqi@0: // All methods that modify the set are not thread-safe except if otherwise noted. aoqi@0: class G1CodeRootSet VALUE_OBJ_CLASS_SPEC { mgerdin@7208: friend class G1CodeRootSetTest; aoqi@0: private: aoqi@0: mgerdin@7208: const static size_t SmallSize = 32; mgerdin@7208: const static size_t Threshold = 24; mgerdin@7208: const static size_t LargeSize = 512; aoqi@0: mgerdin@7208: CodeRootSetTable* _table; mgerdin@7208: CodeRootSetTable* load_acquire_table(); aoqi@0: aoqi@0: size_t _length; mgerdin@7208: mgerdin@7208: void move_to_large(); mgerdin@7208: void allocate_small_table(); aoqi@0: aoqi@0: public: mgerdin@7208: G1CodeRootSet() : _table(NULL), _length(0) {} aoqi@0: ~G1CodeRootSet(); aoqi@0: mgerdin@7208: static void purge(); aoqi@0: mgerdin@7208: static size_t static_mem_size(); aoqi@0: aoqi@0: void add(nmethod* method); aoqi@0: mgerdin@7208: bool remove(nmethod* method); aoqi@0: mgerdin@7208: // Safe to call without synchronization, but may return false negatives. aoqi@0: bool contains(nmethod* method); aoqi@0: aoqi@0: void clear(); aoqi@0: aoqi@0: void nmethods_do(CodeBlobClosure* blk) const; aoqi@0: mgerdin@7208: // Remove all nmethods which no longer contain pointers into our "owner" region mgerdin@7208: void clean(HeapRegion* owner); mgerdin@7208: mgerdin@7208: bool is_empty() { mgerdin@7208: bool empty = length() == 0; mgerdin@7208: assert(empty == (_table == NULL), "is empty only if table is deallocated"); mgerdin@7208: return empty; mgerdin@7208: } aoqi@0: aoqi@0: // Length in elements aoqi@0: size_t length() const { return _length; } aoqi@0: aoqi@0: // Memory size in bytes taken by this set. aoqi@0: size_t mem_size(); aoqi@0: aoqi@0: }; aoqi@0: aoqi@0: #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1CODECACHEREMSET_HPP