src/share/vm/runtime/virtualspace.hpp

changeset 435
a61af66fc99e
child 672
1fdb98a17101
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/runtime/virtualspace.hpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,190 @@
     1.4 +/*
     1.5 + * Copyright 1997-2005 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +// ReservedSpace is a data structure for reserving a contiguous address range.
    1.29 +
    1.30 +class ReservedSpace VALUE_OBJ_CLASS_SPEC {
    1.31 +  friend class VMStructs;
    1.32 + private:
    1.33 +  char*  _base;
    1.34 +  size_t _size;
    1.35 +  size_t _alignment;
    1.36 +  bool   _special;
    1.37 +
    1.38 +  // ReservedSpace
    1.39 +  ReservedSpace(char* base, size_t size, size_t alignment, bool special);
    1.40 +  void initialize(size_t size, size_t alignment, bool large,
    1.41 +                  char* requested_address = NULL);
    1.42 +
    1.43 +  // Release parts of an already-reserved memory region [addr, addr + len) to
    1.44 +  // get a new region that has "compound alignment."  Return the start of the
    1.45 +  // resulting region, or NULL on failure.
    1.46 +  //
    1.47 +  // The region is logically divided into a prefix and a suffix.  The prefix
    1.48 +  // starts at the result address, which is aligned to prefix_align.  The suffix
    1.49 +  // starts at result address + prefix_size, which is aligned to suffix_align.
    1.50 +  // The total size of the result region is size prefix_size + suffix_size.
    1.51 +  char* align_reserved_region(char* addr, const size_t len,
    1.52 +                              const size_t prefix_size,
    1.53 +                              const size_t prefix_align,
    1.54 +                              const size_t suffix_size,
    1.55 +                              const size_t suffix_align);
    1.56 +
    1.57 +  // Reserve memory, call align_reserved_region() to alignment it and return the
    1.58 +  // result.
    1.59 +  char* reserve_and_align(const size_t reserve_size,
    1.60 +                          const size_t prefix_size,
    1.61 +                          const size_t prefix_align,
    1.62 +                          const size_t suffix_size,
    1.63 +                          const size_t suffix_align);
    1.64 +
    1.65 + public:
    1.66 +  // Constructor
    1.67 +  ReservedSpace(size_t size);
    1.68 +  ReservedSpace(size_t size, size_t alignment, bool large,
    1.69 +                char* requested_address = NULL);
    1.70 +  ReservedSpace(const size_t prefix_size, const size_t prefix_align,
    1.71 +                const size_t suffix_size, const size_t suffix_align);
    1.72 +
    1.73 +  // Accessors
    1.74 +  char*  base()      const { return _base;      }
    1.75 +  size_t size()      const { return _size;      }
    1.76 +  size_t alignment() const { return _alignment; }
    1.77 +  bool   special()   const { return _special;   }
    1.78 +
    1.79 +  bool is_reserved() const { return _base != NULL; }
    1.80 +  void release();
    1.81 +
    1.82 +  // Splitting
    1.83 +  ReservedSpace first_part(size_t partition_size, size_t alignment,
    1.84 +                           bool split = false, bool realloc = true);
    1.85 +  ReservedSpace last_part (size_t partition_size, size_t alignment);
    1.86 +
    1.87 +  // These simply call the above using the default alignment.
    1.88 +  inline ReservedSpace first_part(size_t partition_size,
    1.89 +                                  bool split = false, bool realloc = true);
    1.90 +  inline ReservedSpace last_part (size_t partition_size);
    1.91 +
    1.92 +  // Alignment
    1.93 +  static size_t page_align_size_up(size_t size);
    1.94 +  static size_t page_align_size_down(size_t size);
    1.95 +  static size_t allocation_align_size_up(size_t size);
    1.96 +  static size_t allocation_align_size_down(size_t size);
    1.97 +};
    1.98 +
    1.99 +ReservedSpace
   1.100 +ReservedSpace::first_part(size_t partition_size, bool split, bool realloc)
   1.101 +{
   1.102 +  return first_part(partition_size, alignment(), split, realloc);
   1.103 +}
   1.104 +
   1.105 +ReservedSpace ReservedSpace::last_part(size_t partition_size)
   1.106 +{
   1.107 +  return last_part(partition_size, alignment());
   1.108 +}
   1.109 +
   1.110 +// VirtualSpace is data structure for committing a previously reserved address range in smaller chunks.
   1.111 +
   1.112 +class VirtualSpace VALUE_OBJ_CLASS_SPEC {
   1.113 +  friend class VMStructs;
   1.114 + private:
   1.115 +  // Reserved area
   1.116 +  char* _low_boundary;
   1.117 +  char* _high_boundary;
   1.118 +
   1.119 +  // Committed area
   1.120 +  char* _low;
   1.121 +  char* _high;
   1.122 +
   1.123 +  // The entire space has been committed and pinned in memory, no
   1.124 +  // os::commit_memory() or os::uncommit_memory().
   1.125 +  bool _special;
   1.126 +
   1.127 +  // MPSS Support
   1.128 +  // Each virtualspace region has a lower, middle, and upper region.
   1.129 +  // Each region has an end boundary and a high pointer which is the
   1.130 +  // high water mark for the last allocated byte.
   1.131 +  // The lower and upper unaligned to LargePageSizeInBytes uses default page.
   1.132 +  // size.  The middle region uses large page size.
   1.133 +  char* _lower_high;
   1.134 +  char* _middle_high;
   1.135 +  char* _upper_high;
   1.136 +
   1.137 +  char* _lower_high_boundary;
   1.138 +  char* _middle_high_boundary;
   1.139 +  char* _upper_high_boundary;
   1.140 +
   1.141 +  size_t _lower_alignment;
   1.142 +  size_t _middle_alignment;
   1.143 +  size_t _upper_alignment;
   1.144 +
   1.145 +  // MPSS Accessors
   1.146 +  char* lower_high() const { return _lower_high; }
   1.147 +  char* middle_high() const { return _middle_high; }
   1.148 +  char* upper_high() const { return _upper_high; }
   1.149 +
   1.150 +  char* lower_high_boundary() const { return _lower_high_boundary; }
   1.151 +  char* middle_high_boundary() const { return _middle_high_boundary; }
   1.152 +  char* upper_high_boundary() const { return _upper_high_boundary; }
   1.153 +
   1.154 +  size_t lower_alignment() const { return _lower_alignment; }
   1.155 +  size_t middle_alignment() const { return _middle_alignment; }
   1.156 +  size_t upper_alignment() const { return _upper_alignment; }
   1.157 +
   1.158 + public:
   1.159 +  // Committed area
   1.160 +  char* low()  const { return _low; }
   1.161 +  char* high() const { return _high; }
   1.162 +
   1.163 +  // Reserved area
   1.164 +  char* low_boundary()  const { return _low_boundary; }
   1.165 +  char* high_boundary() const { return _high_boundary; }
   1.166 +
   1.167 +  bool special() const { return _special; }
   1.168 +
   1.169 + public:
   1.170 +  // Initialization
   1.171 +  VirtualSpace();
   1.172 +  bool initialize(ReservedSpace rs, size_t committed_byte_size);
   1.173 +
   1.174 +  // Destruction
   1.175 +  ~VirtualSpace();
   1.176 +
   1.177 +  // Testers (all sizes are byte sizes)
   1.178 +  size_t committed_size()   const;
   1.179 +  size_t reserved_size()    const;
   1.180 +  size_t uncommitted_size() const;
   1.181 +  bool   contains(const void* p)  const;
   1.182 +
   1.183 +  // Operations
   1.184 +  // returns true on success, false otherwise
   1.185 +  bool expand_by(size_t bytes, bool pre_touch = false);
   1.186 +  void shrink_by(size_t bytes);
   1.187 +  void release();
   1.188 +
   1.189 +  void check_for_contiguity() PRODUCT_RETURN;
   1.190 +
   1.191 +  // Debugging
   1.192 +  void print() PRODUCT_RETURN;
   1.193 +};

mercurial