src/hotspot/share/gc/parallel/psVirtualspace.hpp
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 35061 hotspot/src/share/vm/gc/parallel/psVirtualspace.hpp@be6025ebffea
child 49621 5ef28d560b6f
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
30291
54cdc5c1a9cb 8068352: Move virtualspace.* out of src/share/vm/runtime to memory directory
coleenp
parents: 22551
diff changeset
     2
 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. 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
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2105
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2105
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2105
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30291
diff changeset
    25
#ifndef SHARE_VM_GC_PARALLEL_PSVIRTUALSPACE_HPP
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30291
diff changeset
    26
#define SHARE_VM_GC_PARALLEL_PSVIRTUALSPACE_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
30291
54cdc5c1a9cb 8068352: Move virtualspace.* out of src/share/vm/runtime to memory directory
coleenp
parents: 22551
diff changeset
    28
#include "memory/virtualspace.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// VirtualSpace for the parallel scavenge collector.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// VirtualSpace is data structure for committing a previously reserved address
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// range in smaller chunks.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    35
class PSVirtualSpace : public CHeapObj<mtGC> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
 protected:
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 13963
diff changeset
    38
  // The space is committed/uncommitted in chunks of size _alignment.  The
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  // ReservedSpace passed to initialize() must be aligned to this value.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  const size_t _alignment;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  // Reserved area
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  char* _reserved_low_addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  char* _reserved_high_addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  // Committed area
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  char* _committed_low_addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  char* _committed_high_addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  // The entire space has been committed and pinned in memory, no
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  // os::commit_memory() or os::uncommit_memory().
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  bool _special;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  // Convenience wrapper.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  inline static size_t pointer_delta(const char* left, const char* right);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  PSVirtualSpace(ReservedSpace rs, size_t alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  PSVirtualSpace(ReservedSpace rs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  ~PSVirtualSpace();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  // Eventually all instances should be created with the above 1- or 2-arg
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  // constructors.  Then the 1st constructor below should become protected and
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  // the 2nd ctor and initialize() removed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  PSVirtualSpace(size_t alignment): _alignment(alignment) { }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  PSVirtualSpace();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  bool initialize(ReservedSpace rs, size_t commit_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  bool contains(void* p)      const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  // Accessors (all sizes are bytes).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  size_t alignment()          const { return _alignment; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  char* reserved_low_addr()   const { return _reserved_low_addr; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  char* reserved_high_addr()  const { return _reserved_high_addr; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  char* committed_low_addr()  const { return _committed_low_addr; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  char* committed_high_addr() const { return _committed_high_addr; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  bool  special()             const { return _special; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  inline size_t committed_size()   const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  inline size_t reserved_size()    const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  inline size_t uncommitted_size() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  // Operations.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  inline  void   set_reserved(char* low_addr, char* high_addr, bool special);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  inline  void   set_reserved(ReservedSpace rs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  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
    88
  virtual bool   expand_by(size_t bytes);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  virtual bool   shrink_by(size_t bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  virtual size_t expand_into(PSVirtualSpace* space, size_t bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  void           release();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  // Debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  static  bool is_aligned(size_t val, size_t align);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
          bool is_aligned(size_t val) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
          bool is_aligned(char* val) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
          void verify() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  virtual bool grows_up() const   { return true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
          bool grows_down() const { return !grows_up(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  // Helper class to verify a space when entering/leaving a block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  class PSVirtualSpaceVerifier: public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
   private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    const PSVirtualSpace* const _space;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
   public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    PSVirtualSpaceVerifier(PSVirtualSpace* space): _space(space) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
      _space->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    ~PSVirtualSpaceVerifier() { _space->verify(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  virtual void print_space_boundaries_on(outputStream* st) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
 // Included for compatibility with the original VirtualSpace.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  // Committed area
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  char* low()  const { return committed_low_addr(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  char* high() const { return committed_high_addr(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  // Reserved area
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  char* low_boundary()  const { return reserved_low_addr(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  char* high_boundary() const { return reserved_high_addr(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
// A virtual space that grows from high addresses to low addresses.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
class PSVirtualSpaceHighToLow : public PSVirtualSpace {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  PSVirtualSpaceHighToLow(ReservedSpace rs, size_t alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  PSVirtualSpaceHighToLow(ReservedSpace rs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
1911
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 1
diff changeset
   134
  virtual bool   expand_by(size_t bytes);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  virtual bool   shrink_by(size_t bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  virtual size_t expand_into(PSVirtualSpace* space, size_t bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  virtual void print_space_boundaries_on(outputStream* st) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  // Debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  virtual bool grows_up() const   { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
// PSVirtualSpace inlines.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
inline size_t
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
PSVirtualSpace::pointer_delta(const char* left, const char* right) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  return ::pointer_delta((void *)left, (void*)right, sizeof(char));
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::committed_size() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  return pointer_delta(committed_high_addr(), committed_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::reserved_size() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  return pointer_delta(reserved_high_addr(), reserved_low_addr());
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 size_t PSVirtualSpace::uncommitted_size() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  return reserved_size() - committed_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
inline void PSVirtualSpace::set_reserved(char* low_addr, char* high_addr, bool special) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  _reserved_low_addr = low_addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  _reserved_high_addr = high_addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  _special = 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_reserved(ReservedSpace rs) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  set_reserved(rs.base(), rs.base() + rs.size(), rs.special());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
inline void PSVirtualSpace::set_committed(char* low_addr, char* high_addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  _committed_low_addr = low_addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  _committed_high_addr = high_addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
}
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   180
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30291
diff changeset
   181
#endif // SHARE_VM_GC_PARALLEL_PSVIRTUALSPACE_HPP