hotspot/src/share/vm/gc_implementation/parallelScavenge/psVirtualspace.hpp
author xdono
Mon, 09 Mar 2009 13:28:46 -0700
changeset 2105 347008ce7984
parent 1911 b7cfe7eb809c
child 5547 f4b087cbb361
permissions -rw-r--r--
6814575: Update copyright year Summary: Update copyright for files that have been modified in 2009, up to 03/09 Reviewed-by: katleman, tbell, ohair
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
2105
347008ce7984 6814575: Update copyright year
xdono
parents: 1911
diff changeset
     2
 * Copyright 2003-2009 Sun Microsystems, Inc.  All Rights Reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
// VirtualSpace for the parallel scavenge collector.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
// VirtualSpace is data structure for committing a previously reserved address
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// range in smaller chunks.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
class PSVirtualSpace : public CHeapObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  // The space is committed/uncommited in chunks of size _alignment.  The
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  // ReservedSpace passed to initialize() must be aligned to this value.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  const size_t _alignment;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  // Reserved area
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  char* _reserved_low_addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  char* _reserved_high_addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  // Committed area
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  char* _committed_low_addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  char* _committed_high_addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  // The entire space has been committed and pinned in memory, no
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  // os::commit_memory() or os::uncommit_memory().
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  bool _special;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  // Convenience wrapper.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  inline static size_t pointer_delta(const char* left, const char* right);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  PSVirtualSpace(ReservedSpace rs, size_t alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  PSVirtualSpace(ReservedSpace rs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  ~PSVirtualSpace();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  // Eventually all instances should be created with the above 1- or 2-arg
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  // constructors.  Then the 1st constructor below should become protected and
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  // the 2nd ctor and initialize() removed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  PSVirtualSpace(size_t alignment): _alignment(alignment) { }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  PSVirtualSpace();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  bool initialize(ReservedSpace rs, size_t commit_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  bool contains(void* p)      const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  // Accessors (all sizes are bytes).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  size_t alignment()          const { return _alignment; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  char* reserved_low_addr()   const { return _reserved_low_addr; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  char* reserved_high_addr()  const { return _reserved_high_addr; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  char* committed_low_addr()  const { return _committed_low_addr; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  char* committed_high_addr() const { return _committed_high_addr; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  bool  special()             const { return _special; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  inline size_t committed_size()   const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  inline size_t reserved_size()    const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  inline size_t uncommitted_size() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  // Operations.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  inline  void   set_reserved(char* low_addr, char* high_addr, bool special);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  inline  void   set_reserved(ReservedSpace rs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  inline  void   set_committed(char* low_addr, char* high_addr);
1911
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 1
diff changeset
    83
  virtual bool   expand_by(size_t bytes);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  virtual bool   shrink_by(size_t bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  virtual size_t expand_into(PSVirtualSpace* space, size_t bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  void           release();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  // Debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  static  bool is_aligned(size_t val, size_t align);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
          bool is_aligned(size_t val) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
          bool is_aligned(char* val) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
          void verify() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
          void print() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  virtual bool grows_up() const   { return true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
          bool grows_down() const { return !grows_up(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  // Helper class to verify a space when entering/leaving a block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  class PSVirtualSpaceVerifier: public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
   private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    const PSVirtualSpace* const _space;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
   public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    PSVirtualSpaceVerifier(PSVirtualSpace* space): _space(space) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
      _space->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    ~PSVirtualSpaceVerifier() { _space->verify(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  virtual void print_space_boundaries_on(outputStream* st) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
 // Included for compatibility with the original VirtualSpace.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  // Committed area
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  char* low()  const { return committed_low_addr(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  char* high() const { return committed_high_addr(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  // Reserved area
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  char* low_boundary()  const { return reserved_low_addr(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  char* high_boundary() const { return reserved_high_addr(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
// A virtual space that grows from high addresses to low addresses.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
class PSVirtualSpaceHighToLow : public PSVirtualSpace {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  PSVirtualSpaceHighToLow(ReservedSpace rs, size_t alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  PSVirtualSpaceHighToLow(ReservedSpace rs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
1911
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 1
diff changeset
   130
  virtual bool   expand_by(size_t bytes);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  virtual bool   shrink_by(size_t bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  virtual size_t expand_into(PSVirtualSpace* space, size_t bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  virtual void print_space_boundaries_on(outputStream* st) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  // Debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  virtual bool grows_up() const   { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
// PSVirtualSpace inlines.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
inline size_t
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
PSVirtualSpace::pointer_delta(const char* left, const char* right) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  return ::pointer_delta((void *)left, (void*)right, sizeof(char));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
inline size_t PSVirtualSpace::committed_size() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  return pointer_delta(committed_high_addr(), committed_low_addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
inline size_t PSVirtualSpace::reserved_size() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  return pointer_delta(reserved_high_addr(), reserved_low_addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
inline size_t PSVirtualSpace::uncommitted_size() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  return reserved_size() - committed_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
inline void PSVirtualSpace::set_reserved(char* low_addr, char* high_addr, bool special) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  _reserved_low_addr = low_addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  _reserved_high_addr = high_addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  _special = special;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
inline void PSVirtualSpace::set_reserved(ReservedSpace rs) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  set_reserved(rs.base(), rs.base() + rs.size(), rs.special());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
inline void PSVirtualSpace::set_committed(char* low_addr, char* high_addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  _committed_low_addr = low_addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  _committed_high_addr = high_addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
}