src/hotspot/share/memory/memRegion.hpp
author coleenp
Wed, 13 Nov 2019 08:23:23 -0500
changeset 59056 15936b142f86
parent 55338 755e82641224
permissions -rw-r--r--
8233913: Remove implicit conversion from Method* to methodHandle Summary: Fix call sites to use existing THREAD local or pass down THREAD local for shallower callsites. Make linkResolver methods return Method* for caller to handleize if needed. Reviewed-by: iklam, thartmann, hseigel
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49455
diff changeset
     2
 * Copyright (c) 2000, 2019, 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: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
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: 1
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
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49455
diff changeset
    25
#ifndef SHARE_MEMORY_MEMREGION_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49455
diff changeset
    26
#define SHARE_MEMORY_MEMREGION_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "memory/allocation.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "utilities/debug.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "utilities/globalDefinitions.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// A very simple data structure representing a contigous region
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// region of address space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
55338
755e82641224 8225478: Make G1CMRootRegions independent of HeapRegions
sangheki
parents: 53792
diff changeset
    35
// Note that MemRegions are typically passed by value, not by reference.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// The intent is that they remain very small and contain no
53758
026e1ea616c8 8218192: Remove copy constructor for MemRegion
manc
parents: 53244
diff changeset
    37
// objects. The copy constructor and destructor must be trivial,
026e1ea616c8 8218192: Remove copy constructor for MemRegion
manc
parents: 53244
diff changeset
    38
// to support optimization for pass-by-value.
55338
755e82641224 8225478: Make G1CMRootRegions independent of HeapRegions
sangheki
parents: 53792
diff changeset
    39
// These should almost never be allocated in heap but we do
755e82641224 8225478: Make G1CMRootRegions independent of HeapRegions
sangheki
parents: 53792
diff changeset
    40
// create MemRegions (in CardTable and G1CMRootMemRegions) on the heap so operator
755e82641224 8225478: Make G1CMRootRegions independent of HeapRegions
sangheki
parents: 53792
diff changeset
    41
// new and operator new [] were added for these special cases.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
49364
601146c66cad 8173070: Remove ValueObj class for allocation subclassing for runtime code
coleenp
parents: 47216
diff changeset
    43
class MemRegion {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  HeapWord* _start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  size_t    _word_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  MemRegion() : _start(NULL), _word_size(0) {};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  MemRegion(HeapWord* start, size_t word_size) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    _start(start), _word_size(word_size) {};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  MemRegion(HeapWord* start, HeapWord* end) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    _start(start), _word_size(pointer_delta(end, start)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    assert(end >= start, "incorrect constructor arguments");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    57
  MemRegion(MetaWord* start, MetaWord* end) :
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    58
    _start((HeapWord*)start), _word_size(pointer_delta(end, start)) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    59
    assert(end >= start, "incorrect constructor arguments");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    60
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  MemRegion intersection(const MemRegion mr2) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  // regions must overlap or be adjacent
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  MemRegion _union(const MemRegion mr2) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  // minus will fail a guarantee if mr2 is interior to this,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  // since there's no way to return 2 disjoint regions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  MemRegion minus(const MemRegion mr2) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  HeapWord* start() const { return _start; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  HeapWord* end() const   { return _start + _word_size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  HeapWord* last() const  { return _start + _word_size - 1; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  void set_start(HeapWord* start) { _start = start; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  void set_end(HeapWord* end)     { _word_size = pointer_delta(end, _start); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  void set_word_size(size_t word_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    _word_size = word_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  bool contains(const MemRegion mr2) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    return _start <= mr2._start && end() >= mr2.end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  bool contains(const void* addr) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    return addr >= (void*)_start && addr < (void*)end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  bool equals(const MemRegion mr2) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    // first disjunct since we do not have a canonical empty set
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    return ((is_empty() && mr2.is_empty()) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
            (start() == mr2.start() && end() == mr2.end()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  size_t byte_size() const { return _word_size * sizeof(HeapWord); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  size_t word_size() const { return _word_size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  bool is_empty() const { return word_size() == 0; }
19696
bd5a0131bde1 8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents: 17376
diff changeset
    95
  void* operator new(size_t size) throw();
bd5a0131bde1 8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents: 17376
diff changeset
    96
  void* operator new [](size_t size) throw();
17376
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 13728
diff changeset
    97
  void  operator delete(void* p);
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 13728
diff changeset
    98
  void  operator delete [](void* p);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
// For iteration over MemRegion's.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
class MemRegionClosure : public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  virtual void do_MemRegion(MemRegion mr) = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
// A ResourceObj version of MemRegionClosure
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
class MemRegionClosureRO: public MemRegionClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
public:
19696
bd5a0131bde1 8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents: 17376
diff changeset
   112
  void* operator new(size_t size, ResourceObj::allocation_type type, MEMFLAGS flags) throw() {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   113
        return ResourceObj::operator new(size, type, flags);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  }
19696
bd5a0131bde1 8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents: 17376
diff changeset
   115
  void* operator new(size_t size, Arena *arena) throw() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
        return ResourceObj::operator new(size, arena);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  }
19696
bd5a0131bde1 8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents: 17376
diff changeset
   118
  void* operator new(size_t size) throw() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
        return ResourceObj::operator new(size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  void  operator delete(void* p) {} // nothing to do
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   124
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49455
diff changeset
   125
#endif // SHARE_MEMORY_MEMREGION_HPP