view src/share/vm/runtime/virtualspace.hpp @ 340:9ee9cf798b59

6754988: Update copyright year Summary: Update for files that have been modified starting July 2008 Reviewed-by: ohair, tbell
author xdono
date Thu, 02 Oct 2008 19:58:19 -0700
parents 1fdb98a17101
children 660978a2a31a
line wrap: on
line source
 * Copyright 1997-2008 Sun Microsystems, Inc.  All Rights Reserved.
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 * CA 95054 USA or visit if you need additional information or
 * have any questions.

// ReservedSpace is a data structure for reserving a contiguous address range.

class ReservedSpace VALUE_OBJ_CLASS_SPEC {
  friend class VMStructs;
  char*  _base;
  size_t _size;
  size_t _noaccess_prefix;
  size_t _alignment;
  bool   _special;

  // ReservedSpace
  ReservedSpace(char* base, size_t size, size_t alignment, bool special);
  void initialize(size_t size, size_t alignment, bool large,
                  char* requested_address,
                  const size_t noaccess_prefix);

  // Release parts of an already-reserved memory region [addr, addr + len) to
  // get a new region that has "compound alignment."  Return the start of the
  // resulting region, or NULL on failure.
  // The region is logically divided into a prefix and a suffix.  The prefix
  // starts at the result address, which is aligned to prefix_align.  The suffix
  // starts at result address + prefix_size, which is aligned to suffix_align.
  // The total size of the result region is size prefix_size + suffix_size.
  char* align_reserved_region(char* addr, const size_t len,
                              const size_t prefix_size,
                              const size_t prefix_align,
                              const size_t suffix_size,
                              const size_t suffix_align);

  // Reserve memory, call align_reserved_region() to alignment it and return the
  // result.
  char* reserve_and_align(const size_t reserve_size,
                          const size_t prefix_size,
                          const size_t prefix_align,
                          const size_t suffix_size,
                          const size_t suffix_align);

  // Create protection page at the beginning of the space.
  void protect_noaccess_prefix(const size_t size);

  // Constructor
  ReservedSpace(size_t size);
  ReservedSpace(size_t size, size_t alignment, bool large,
                char* requested_address = NULL,
                const size_t noaccess_prefix = 0);
  ReservedSpace(const size_t prefix_size, const size_t prefix_align,
                const size_t suffix_size, const size_t suffix_align,
                const size_t noaccess_prefix);

  // Accessors
  char*  base()      const { return _base;      }
  size_t size()      const { return _size;      }
  size_t alignment() const { return _alignment; }
  bool   special()   const { return _special;   }

  size_t noaccess_prefix()   const { return _noaccess_prefix;   }

  bool is_reserved() const { return _base != NULL; }
  void release();

  // Splitting
  ReservedSpace first_part(size_t partition_size, size_t alignment,
                           bool split = false, bool realloc = true);
  ReservedSpace last_part (size_t partition_size, size_t alignment);

  // These simply call the above using the default alignment.
  inline ReservedSpace first_part(size_t partition_size,
                                  bool split = false, bool realloc = true);
  inline ReservedSpace last_part (size_t partition_size);

  // Alignment
  static size_t page_align_size_up(size_t size);
  static size_t page_align_size_down(size_t size);
  static size_t allocation_align_size_up(size_t size);
  static size_t allocation_align_size_down(size_t size);

ReservedSpace::first_part(size_t partition_size, bool split, bool realloc)
  return first_part(partition_size, alignment(), split, realloc);

ReservedSpace ReservedSpace::last_part(size_t partition_size)
  return last_part(partition_size, alignment());

// Class encapsulating behavior specific of memory space reserved for Java heap
class ReservedHeapSpace : public ReservedSpace {
  // Constructor
  ReservedHeapSpace(size_t size, size_t forced_base_alignment,
                    bool large, char* requested_address);
  ReservedHeapSpace(const size_t prefix_size, const size_t prefix_align,
                    const size_t suffix_size, const size_t suffix_align);

// VirtualSpace is data structure for committing a previously reserved address range in smaller chunks.

class VirtualSpace VALUE_OBJ_CLASS_SPEC {
  friend class VMStructs;
  // Reserved area
  char* _low_boundary;
  char* _high_boundary;

  // Committed area
  char* _low;
  char* _high;

  // The entire space has been committed and pinned in memory, no
  // os::commit_memory() or os::uncommit_memory().
  bool _special;

  // MPSS Support
  // Each virtualspace region has a lower, middle, and upper region.
  // Each region has an end boundary and a high pointer which is the
  // high water mark for the last allocated byte.
  // The lower and upper unaligned to LargePageSizeInBytes uses default page.
  // size.  The middle region uses large page size.
  char* _lower_high;
  char* _middle_high;
  char* _upper_high;

  char* _lower_high_boundary;
  char* _middle_high_boundary;
  char* _upper_high_boundary;

  size_t _lower_alignment;
  size_t _middle_alignment;
  size_t _upper_alignment;

  // MPSS Accessors
  char* lower_high() const { return _lower_high; }
  char* middle_high() const { return _middle_high; }
  char* upper_high() const { return _upper_high; }

  char* lower_high_boundary() const { return _lower_high_boundary; }
  char* middle_high_boundary() const { return _middle_high_boundary; }
  char* upper_high_boundary() const { return _upper_high_boundary; }

  size_t lower_alignment() const { return _lower_alignment; }
  size_t middle_alignment() const { return _middle_alignment; }
  size_t upper_alignment() const { return _upper_alignment; }

  // Committed area
  char* low()  const { return _low; }
  char* high() const { return _high; }

  // Reserved area
  char* low_boundary()  const { return _low_boundary; }
  char* high_boundary() const { return _high_boundary; }

  bool special() const { return _special; }

  // Initialization
  bool initialize(ReservedSpace rs, size_t committed_byte_size);

  // Destruction

  // Testers (all sizes are byte sizes)
  size_t committed_size()   const;
  size_t reserved_size()    const;
  size_t uncommitted_size() const;
  bool   contains(const void* p)  const;

  // Operations
  // returns true on success, false otherwise
  bool expand_by(size_t bytes, bool pre_touch = false);
  void shrink_by(size_t bytes);
  void release();

  void check_for_contiguity() PRODUCT_RETURN;

  // Debugging
  void print() PRODUCT_RETURN;