src/share/vm/runtime/virtualspace.hpp

Thu, 02 Oct 2008 19:58:19 -0700

author
xdono
date
Thu, 02 Oct 2008 19:58:19 -0700
changeset 772
9ee9cf798b59
parent 672
1fdb98a17101
child 1077
660978a2a31a
permissions
-rw-r--r--

6754988: Update copyright year
Summary: Update for files that have been modified starting July 2008
Reviewed-by: ohair, tbell

     1 /*
     2  * Copyright 1997-2008 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  *
    23  */
    25 // ReservedSpace is a data structure for reserving a contiguous address range.
    27 class ReservedSpace VALUE_OBJ_CLASS_SPEC {
    28   friend class VMStructs;
    29  private:
    30   char*  _base;
    31   size_t _size;
    32   size_t _noaccess_prefix;
    33   size_t _alignment;
    34   bool   _special;
    36   // ReservedSpace
    37   ReservedSpace(char* base, size_t size, size_t alignment, bool special);
    38   void initialize(size_t size, size_t alignment, bool large,
    39                   char* requested_address,
    40                   const size_t noaccess_prefix);
    42   // Release parts of an already-reserved memory region [addr, addr + len) to
    43   // get a new region that has "compound alignment."  Return the start of the
    44   // resulting region, or NULL on failure.
    45   //
    46   // The region is logically divided into a prefix and a suffix.  The prefix
    47   // starts at the result address, which is aligned to prefix_align.  The suffix
    48   // starts at result address + prefix_size, which is aligned to suffix_align.
    49   // The total size of the result region is size prefix_size + suffix_size.
    50   char* align_reserved_region(char* addr, const size_t len,
    51                               const size_t prefix_size,
    52                               const size_t prefix_align,
    53                               const size_t suffix_size,
    54                               const size_t suffix_align);
    56   // Reserve memory, call align_reserved_region() to alignment it and return the
    57   // result.
    58   char* reserve_and_align(const size_t reserve_size,
    59                           const size_t prefix_size,
    60                           const size_t prefix_align,
    61                           const size_t suffix_size,
    62                           const size_t suffix_align);
    64  protected:
    65   // Create protection page at the beginning of the space.
    66   void protect_noaccess_prefix(const size_t size);
    68  public:
    69   // Constructor
    70   ReservedSpace(size_t size);
    71   ReservedSpace(size_t size, size_t alignment, bool large,
    72                 char* requested_address = NULL,
    73                 const size_t noaccess_prefix = 0);
    74   ReservedSpace(const size_t prefix_size, const size_t prefix_align,
    75                 const size_t suffix_size, const size_t suffix_align,
    76                 const size_t noaccess_prefix);
    78   // Accessors
    79   char*  base()      const { return _base;      }
    80   size_t size()      const { return _size;      }
    81   size_t alignment() const { return _alignment; }
    82   bool   special()   const { return _special;   }
    84   size_t noaccess_prefix()   const { return _noaccess_prefix;   }
    86   bool is_reserved() const { return _base != NULL; }
    87   void release();
    89   // Splitting
    90   ReservedSpace first_part(size_t partition_size, size_t alignment,
    91                            bool split = false, bool realloc = true);
    92   ReservedSpace last_part (size_t partition_size, size_t alignment);
    94   // These simply call the above using the default alignment.
    95   inline ReservedSpace first_part(size_t partition_size,
    96                                   bool split = false, bool realloc = true);
    97   inline ReservedSpace last_part (size_t partition_size);
    99   // Alignment
   100   static size_t page_align_size_up(size_t size);
   101   static size_t page_align_size_down(size_t size);
   102   static size_t allocation_align_size_up(size_t size);
   103   static size_t allocation_align_size_down(size_t size);
   104 };
   106 ReservedSpace
   107 ReservedSpace::first_part(size_t partition_size, bool split, bool realloc)
   108 {
   109   return first_part(partition_size, alignment(), split, realloc);
   110 }
   112 ReservedSpace ReservedSpace::last_part(size_t partition_size)
   113 {
   114   return last_part(partition_size, alignment());
   115 }
   117 // Class encapsulating behavior specific of memory space reserved for Java heap
   118 class ReservedHeapSpace : public ReservedSpace {
   119 public:
   120   // Constructor
   121   ReservedHeapSpace(size_t size, size_t forced_base_alignment,
   122                     bool large, char* requested_address);
   123   ReservedHeapSpace(const size_t prefix_size, const size_t prefix_align,
   124                     const size_t suffix_size, const size_t suffix_align);
   125 };
   127 // VirtualSpace is data structure for committing a previously reserved address range in smaller chunks.
   129 class VirtualSpace VALUE_OBJ_CLASS_SPEC {
   130   friend class VMStructs;
   131  private:
   132   // Reserved area
   133   char* _low_boundary;
   134   char* _high_boundary;
   136   // Committed area
   137   char* _low;
   138   char* _high;
   140   // The entire space has been committed and pinned in memory, no
   141   // os::commit_memory() or os::uncommit_memory().
   142   bool _special;
   144   // MPSS Support
   145   // Each virtualspace region has a lower, middle, and upper region.
   146   // Each region has an end boundary and a high pointer which is the
   147   // high water mark for the last allocated byte.
   148   // The lower and upper unaligned to LargePageSizeInBytes uses default page.
   149   // size.  The middle region uses large page size.
   150   char* _lower_high;
   151   char* _middle_high;
   152   char* _upper_high;
   154   char* _lower_high_boundary;
   155   char* _middle_high_boundary;
   156   char* _upper_high_boundary;
   158   size_t _lower_alignment;
   159   size_t _middle_alignment;
   160   size_t _upper_alignment;
   162   // MPSS Accessors
   163   char* lower_high() const { return _lower_high; }
   164   char* middle_high() const { return _middle_high; }
   165   char* upper_high() const { return _upper_high; }
   167   char* lower_high_boundary() const { return _lower_high_boundary; }
   168   char* middle_high_boundary() const { return _middle_high_boundary; }
   169   char* upper_high_boundary() const { return _upper_high_boundary; }
   171   size_t lower_alignment() const { return _lower_alignment; }
   172   size_t middle_alignment() const { return _middle_alignment; }
   173   size_t upper_alignment() const { return _upper_alignment; }
   175  public:
   176   // Committed area
   177   char* low()  const { return _low; }
   178   char* high() const { return _high; }
   180   // Reserved area
   181   char* low_boundary()  const { return _low_boundary; }
   182   char* high_boundary() const { return _high_boundary; }
   184   bool special() const { return _special; }
   186  public:
   187   // Initialization
   188   VirtualSpace();
   189   bool initialize(ReservedSpace rs, size_t committed_byte_size);
   191   // Destruction
   192   ~VirtualSpace();
   194   // Testers (all sizes are byte sizes)
   195   size_t committed_size()   const;
   196   size_t reserved_size()    const;
   197   size_t uncommitted_size() const;
   198   bool   contains(const void* p)  const;
   200   // Operations
   201   // returns true on success, false otherwise
   202   bool expand_by(size_t bytes, bool pre_touch = false);
   203   void shrink_by(size_t bytes);
   204   void release();
   206   void check_for_contiguity() PRODUCT_RETURN;
   208   // Debugging
   209   void print() PRODUCT_RETURN;
   210 };

mercurial