1 /*
2  * Copyright (c) 2017, 2018, 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  */
24 
25 #ifndef SHARE_VM_JFR_RECORDER_STORAGE_JFRVIRTUALMEMORY_HPP
26 #define SHARE_VM_JFR_RECORDER_STORAGE_JFRVIRTUALMEMORY_HPP
27 
28 #include "jfr/utilities/jfrAllocation.hpp"
29 
30 class JfrVirtualMemoryManager;
31 
32 class JfrVirtualMemory : public JfrCHeapObj {
33  private:
34   JfrVirtualMemoryManager* _vmm;
35   const u1* _reserved_low; // lowest address of reservation
36   const u1* _reserved_high; // highest address of reservation
37   u1* _top; // current allocation address
38   const u1* _commit_point; // synch points for committing new memory
39   size_t _physical_commit_size_request_words; // aligned to os::vm_allocation_granularity()
40   size_t _aligned_datum_size_bytes; // datum alignment
41 
42   bool commit_memory_block();
43   void* commit(size_t block_size_request_words);
44   void* index_ptr(size_t index); // index to address map
45 
46  public:
47   JfrVirtualMemory();
48   ~JfrVirtualMemory();
49 
50   // initialization will do the reservation and return it
51   void* initialize(size_t reservation_size_request_bytes, size_t block_size_request_bytes, size_t datum_size_bytes = 1);
52 
53   void* new_datum(); // datum oriented allocation
54   void* get(size_t index); // direct access retrieval
55   size_t aligned_datum_size_bytes() const;
56 
57   bool is_full() const; // limit of reservation committed and in use
58   bool is_empty() const;
59 
60   size_t count() const; // how many
61   size_t live_set() const; // how much resident memory (actually in use)
62   size_t reserved_size() const; // size of reservation
63   bool compact(size_t index);
64 };
65 
66 #endif // SHARE_VM_JFR_RECORDER_STORAGE_JFRVIRTUALMEMORY_HPP
67