hotspot/src/share/vm/gc_implementation/g1/g1PageBasedVirtualSpace.hpp
author tschatzl
Tue, 26 Aug 2014 09:36:53 +0200
changeset 26316 93f6b40c038b
parent 26160 aba6b01cb988
child 28482 e1a8d03c342f
permissions -rw-r--r--
8054819: Rename HeapRegionSeq to HeapRegionManager Reviewed-by: jwilhelm, jmasa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
     1
/*
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
     4
 *
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
     7
 * published by the Free Software Foundation.
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
     8
 *
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    13
 * accompanied this code).
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    14
 *
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    18
 *
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    21
 * questions.
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    22
 *
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    23
 */
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    24
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    25
#ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1PAGEBASEDVIRTUALSPACE_HPP
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    26
#define SHARE_VM_GC_IMPLEMENTATION_G1_G1PAGEBASEDVIRTUALSPACE_HPP
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    27
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    28
#include "memory/allocation.hpp"
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    29
#include "memory/memRegion.hpp"
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    30
#include "runtime/virtualspace.hpp"
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    31
#include "utilities/bitMap.hpp"
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    32
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    33
// Virtual space management helper for a virtual space with an OS page allocation
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    34
// granularity.
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    35
// (De-)Allocation requests are always OS page aligned by passing a page index
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    36
// and multiples of pages.
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    37
// The implementation gives an error when trying to commit or uncommit pages that
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    38
// have already been committed or uncommitted.
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    39
class G1PageBasedVirtualSpace VALUE_OBJ_CLASS_SPEC {
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    40
  friend class VMStructs;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    41
 private:
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    42
  // Reserved area addresses.
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    43
  char* _low_boundary;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    44
  char* _high_boundary;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    45
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    46
  // The commit/uncommit granularity in bytes.
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    47
  size_t _page_size;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    48
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    49
  // Bitmap used for verification of commit/uncommit operations.
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    50
  BitMap _committed;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    51
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    52
  // Indicates that the entire space has been committed and pinned in memory,
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    53
  // os::commit_memory() or os::uncommit_memory() have no function.
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    54
  bool _special;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    55
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    56
  // Indicates whether the committed space should be executable.
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    57
  bool _executable;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    58
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    59
  // Returns the index of the page which contains the given address.
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    60
  uintptr_t  addr_to_page_index(char* addr) const;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    61
  // Returns the address of the given page index.
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    62
  char*  page_start(uintptr_t index);
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    63
  // Returns the byte size of the given number of pages.
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    64
  size_t byte_size_for_pages(size_t num);
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    65
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    66
  // Returns true if the entire area is backed by committed memory.
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    67
  bool is_area_committed(uintptr_t start, size_t size_in_pages) const;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    68
  // Returns true if the entire area is not backed by committed memory.
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    69
  bool is_area_uncommitted(uintptr_t start, size_t size_in_pages) const;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    70
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    71
 public:
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    72
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    73
  // Commit the given area of pages starting at start being size_in_pages large.
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    74
  MemRegion commit(uintptr_t start, size_t size_in_pages);
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    75
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    76
  // Uncommit the given area of pages starting at start being size_in_pages large.
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    77
  MemRegion uncommit(uintptr_t start, size_t size_in_pages);
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    78
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    79
  bool special() const { return _special; }
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    80
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    81
  // Initialization
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    82
  G1PageBasedVirtualSpace();
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    83
  bool initialize_with_granularity(ReservedSpace rs, size_t page_size);
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    84
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    85
  // Destruction
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    86
  ~G1PageBasedVirtualSpace();
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    87
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    88
  // Amount of reserved memory.
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    89
  size_t reserved_size() const;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    90
  // Memory used in this virtual space.
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    91
  size_t committed_size() const;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    92
  // Memory left to use/expand in this virtual space.
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    93
  size_t uncommitted_size() const;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    94
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    95
  bool contains(const void* p) const;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    96
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    97
  MemRegion reserved() {
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    98
    MemRegion x((HeapWord*)_low_boundary, reserved_size() / HeapWordSize);
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    99
    return x;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   100
  }
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   101
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   102
  void release();
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   103
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   104
  void check_for_contiguity() PRODUCT_RETURN;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   105
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   106
  // Debugging
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   107
  void print_on(outputStream* out) PRODUCT_RETURN;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   108
  void print();
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   109
};
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   110
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   111
#endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1PAGEBASEDVIRTUALSPACE_HPP