tschatzl@7051: /* azakharov@7835: * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. tschatzl@7051: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. tschatzl@7051: * tschatzl@7051: * This code is free software; you can redistribute it and/or modify it tschatzl@7051: * under the terms of the GNU General Public License version 2 only, as tschatzl@7051: * published by the Free Software Foundation. tschatzl@7051: * tschatzl@7051: * This code is distributed in the hope that it will be useful, but WITHOUT tschatzl@7051: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or tschatzl@7051: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License tschatzl@7051: * version 2 for more details (a copy is included in the LICENSE file that tschatzl@7051: * accompanied this code). tschatzl@7051: * tschatzl@7051: * You should have received a copy of the GNU General Public License version tschatzl@7051: * 2 along with this work; if not, write to the Free Software Foundation, tschatzl@7051: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. tschatzl@7051: * tschatzl@7051: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA tschatzl@7051: * or visit www.oracle.com if you need additional information or have any tschatzl@7051: * questions. tschatzl@7051: * tschatzl@7051: */ tschatzl@7051: tschatzl@7051: #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1REGIONTOSPACEMAPPER_HPP tschatzl@7051: #define SHARE_VM_GC_IMPLEMENTATION_G1_G1REGIONTOSPACEMAPPER_HPP tschatzl@7051: tschatzl@7051: #include "gc_implementation/g1/g1PageBasedVirtualSpace.hpp" tschatzl@7053: #include "memory/allocation.hpp" tschatzl@7051: #include "utilities/debug.hpp" tschatzl@7051: tschatzl@7051: class G1MappingChangedListener VALUE_OBJ_CLASS_SPEC { tschatzl@7051: public: tschatzl@7051: // Fired after commit of the memory, i.e. the memory this listener is registered tschatzl@7051: // for can be accessed. tschatzl@7257: // Zero_filled indicates that the memory can be considered as filled with zero bytes tschatzl@7257: // when called. tschatzl@7257: virtual void on_commit(uint start_idx, size_t num_regions, bool zero_filled) = 0; tschatzl@7051: }; tschatzl@7051: tschatzl@7051: // Maps region based commit/uncommit requests to the underlying page sized virtual tschatzl@7051: // space. tschatzl@7051: class G1RegionToSpaceMapper : public CHeapObj { tschatzl@7051: private: tschatzl@7051: G1MappingChangedListener* _listener; tschatzl@7051: protected: tschatzl@7051: // Backing storage. tschatzl@7051: G1PageBasedVirtualSpace _storage; tschatzl@7781: tschatzl@7051: size_t _region_granularity; tschatzl@7051: // Mapping management tschatzl@7051: BitMap _commit_map; tschatzl@7051: tschatzl@7781: G1RegionToSpaceMapper(ReservedSpace rs, size_t used_size, size_t page_size, size_t region_granularity, MemoryType type); tschatzl@7051: tschatzl@7257: void fire_on_commit(uint start_idx, size_t num_regions, bool zero_filled); tschatzl@7051: public: tschatzl@7051: MemRegion reserved() { return _storage.reserved(); } tschatzl@7051: azakharov@7835: size_t reserved_size() { return _storage.reserved_size(); } azakharov@7835: size_t committed_size() { return _storage.committed_size(); } azakharov@7835: tschatzl@7051: void set_mapping_changed_listener(G1MappingChangedListener* listener) { _listener = listener; } tschatzl@7051: tschatzl@7051: virtual ~G1RegionToSpaceMapper() { tschatzl@7051: _commit_map.resize(0, /* in_resource_area */ false); tschatzl@7051: } tschatzl@7051: tschatzl@7051: bool is_committed(uintptr_t idx) const { tschatzl@7051: return _commit_map.at(idx); tschatzl@7051: } tschatzl@7051: tschatzl@7781: virtual void commit_regions(uint start_idx, size_t num_regions = 1) = 0; tschatzl@7781: virtual void uncommit_regions(uint start_idx, size_t num_regions = 1) = 0; tschatzl@7051: tschatzl@7051: // Creates an appropriate G1RegionToSpaceMapper for the given parameters. tschatzl@7781: // The actual space to be used within the given reservation is given by actual_size. tschatzl@7781: // This is because some OSes need to round up the reservation size to guarantee tschatzl@7781: // alignment of page_size. tschatzl@7051: // The byte_translation_factor defines how many bytes in a region correspond to tschatzl@7051: // a single byte in the data structure this mapper is for. tschatzl@7051: // Eg. in the card table, this value corresponds to the size a single card tschatzl@7781: // table entry corresponds to in the heap. tschatzl@7051: static G1RegionToSpaceMapper* create_mapper(ReservedSpace rs, tschatzl@7781: size_t actual_size, tschatzl@7781: size_t page_size, tschatzl@7051: size_t region_granularity, tschatzl@7051: size_t byte_translation_factor, tschatzl@7051: MemoryType type); tschatzl@7051: }; tschatzl@7051: tschatzl@7051: #endif /* SHARE_VM_GC_IMPLEMENTATION_G1_G1REGIONTOSPACEMAPPER_HPP */