src/hotspot/share/memory/heap.hpp
author lucy
Wed, 20 Nov 2019 09:12:07 +0100
changeset 59145 ea044aedc2b6
parent 54943 6cbb5c2255e3
permissions -rw-r--r--
8231460: Performance issue (CodeHeap) with large free blocks Reviewed-by: adinn, stuefe
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: 49611
diff changeset
     2
 * Copyright (c) 1997, 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: 49611
diff changeset
    25
#ifndef SHARE_MEMORY_HEAP_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49611
diff changeset
    26
#define SHARE_MEMORY_HEAP_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    27
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 23214
diff changeset
    28
#include "code/codeBlob.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    29
#include "memory/allocation.hpp"
30291
54cdc5c1a9cb 8068352: Move virtualspace.* out of src/share/vm/runtime to memory directory
coleenp
parents: 28493
diff changeset
    30
#include "memory/virtualspace.hpp"
31620
53be635ad49c 8087333: Optionally Pre-Generate the HotSpot Template Interpreter
bdelsart
parents: 30291
diff changeset
    31
#include "utilities/macros.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    32
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// Blocks
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
49364
601146c66cad 8173070: Remove ValueObj class for allocation subclassing for runtime code
coleenp
parents: 47768
diff changeset
    35
class HeapBlock {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  struct Header {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
    size_t  _length;                             // the length in segments
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
    bool    _used;                               // Used bit
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  union {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    Header _header;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
    int64_t _padding[ (sizeof(Header) + sizeof(int64_t)-1) / sizeof(int64_t) ];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
                        // pad to 0 mod 8
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  // Initialization
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  void initialize(size_t length)                 { _header._length = length; set_used(); }
54943
6cbb5c2255e3 8223444: Improve CodeHeap Free Space Management
lucy
parents: 53244
diff changeset
    54
  // Merging/splitting
6cbb5c2255e3 8223444: Improve CodeHeap Free Space Management
lucy
parents: 53244
diff changeset
    55
  void set_length(size_t length)                 { _header._length = length; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  // Accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  void* allocated_space() const                  { return (void*)(this + 1); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  size_t length() const                          { return _header._length; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  // Used/free
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  void set_used()                                { _header._used = true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  void set_free()                                { _header._used = false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  bool free()                                    { return !_header._used; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
class FreeBlock: public HeapBlock {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  FreeBlock* _link;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  // Initialization
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  void initialize(size_t length)             { HeapBlock::initialize(length); _link= NULL; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  // Accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  FreeBlock* link() const                    { return _link; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  void set_link(FreeBlock* link)             { _link = link; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7715
diff changeset
    81
class CodeHeap : public CHeapObj<mtCode> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  friend class VMStructs;
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 34158
diff changeset
    83
 protected:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  VirtualSpace _memory;                          // the memory holding the blocks
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  VirtualSpace _segmap;                          // the memory holding the segment map
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  size_t       _number_of_committed_segments;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  size_t       _number_of_reserved_segments;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  size_t       _segment_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  int          _log2_segment_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  size_t       _next_segment;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  FreeBlock*   _freelist;
59145
ea044aedc2b6 8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents: 54943
diff changeset
    95
  FreeBlock*   _last_insert_point;               // last insert point in add_to_freelist
17016
78b1c3670525 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 13963
diff changeset
    96
  size_t       _freelist_segments;               // No. of segments in freelist
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
    97
  int          _freelist_length;
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 23214
diff changeset
    98
  size_t       _max_allocated_capacity;          // Peak capacity that was allocated during lifetime of the heap
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 23214
diff changeset
    99
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 23214
diff changeset
   100
  const char*  _name;                            // Name of the CodeHeap
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 23214
diff changeset
   101
  const int    _code_blob_type;                  // CodeBlobType it contains
34158
1f8d643b02d5 8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents: 31620
diff changeset
   102
  int          _blob_count;                      // Number of CodeBlobs
1f8d643b02d5 8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents: 31620
diff changeset
   103
  int          _nmethod_count;                   // Number of nmethods
1f8d643b02d5 8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents: 31620
diff changeset
   104
  int          _adapter_count;                   // Number of adapters
1f8d643b02d5 8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents: 31620
diff changeset
   105
  int          _full_count;                      // Number of times the code heap was full
59145
ea044aedc2b6 8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents: 54943
diff changeset
   106
  int          _fragmentation_count;             // #FreeBlock joins without fully initializing segment map elements.
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   107
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   108
  enum { free_sentinel = 0xFF };
59145
ea044aedc2b6 8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents: 54943
diff changeset
   109
  static const int fragmentation_limit = 10000;  // defragment after that many potential fragmentations.
ea044aedc2b6 8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents: 54943
diff changeset
   110
  static const int freelist_limit = 100;         // improve insert point search if list is longer than this limit.
ea044aedc2b6 8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents: 54943
diff changeset
   111
  static char  segmap_template[free_sentinel+1];
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  // Helper functions
17016
78b1c3670525 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 13963
diff changeset
   114
  size_t   size_to_segments(size_t size) const { return (size + _segment_size - 1) >> _log2_segment_size; }
78b1c3670525 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 13963
diff changeset
   115
  size_t   segments_to_size(size_t number_of_segments) const { return number_of_segments << _log2_segment_size; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  size_t   segment_for(void* p) const            { return ((char*)p - _memory.low()) >> _log2_segment_size; }
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   118
  bool     is_segment_unused(int val) const      { return val == free_sentinel; }
59145
ea044aedc2b6 8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents: 54943
diff changeset
   119
  void*    address_for(size_t i) const           { return (void*)(_memory.low() + segments_to_size(i)); }
ea044aedc2b6 8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents: 54943
diff changeset
   120
  void*    find_block_for(void* p) const;
ea044aedc2b6 8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents: 54943
diff changeset
   121
  HeapBlock* block_at(size_t i) const            { return (HeapBlock*)address_for(i); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
54943
6cbb5c2255e3 8223444: Improve CodeHeap Free Space Management
lucy
parents: 53244
diff changeset
   123
  // These methods take segment map indices as range boundaries
6cbb5c2255e3 8223444: Improve CodeHeap Free Space Management
lucy
parents: 53244
diff changeset
   124
  void mark_segmap_as_free(size_t beg, size_t end);
59145
ea044aedc2b6 8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents: 54943
diff changeset
   125
  void mark_segmap_as_used(size_t beg, size_t end, bool is_FreeBlock_join);
54943
6cbb5c2255e3 8223444: Improve CodeHeap Free Space Management
lucy
parents: 53244
diff changeset
   126
  void invalidate(size_t beg, size_t end, size_t header_bytes);
6cbb5c2255e3 8223444: Improve CodeHeap Free Space Management
lucy
parents: 53244
diff changeset
   127
  void clear(size_t beg, size_t end);
6cbb5c2255e3 8223444: Improve CodeHeap Free Space Management
lucy
parents: 53244
diff changeset
   128
  void clear();                                 // clears all heap contents
59145
ea044aedc2b6 8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents: 54943
diff changeset
   129
  static void init_segmap_template();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  // Freelist management helpers
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   132
  FreeBlock* following_block(FreeBlock* b);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  void insert_after(FreeBlock* a, FreeBlock* b);
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   134
  bool merge_right (FreeBlock* a);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  // Toplevel freelist management
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   137
  void add_to_freelist(HeapBlock* b);
54943
6cbb5c2255e3 8223444: Improve CodeHeap Free Space Management
lucy
parents: 53244
diff changeset
   138
  HeapBlock* search_freelist(size_t length);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  // Iteration helpers
28493
26cabf3261fa 8065894: CodeHeap::next_free should be renamed
zmajo
parents: 27420
diff changeset
   141
  void*      next_used(HeapBlock* b) const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  HeapBlock* block_start(void* p) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  // to perform additional actions on creation of executable code
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  void on_code_mapping(char* base, size_t size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
 public:
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 23214
diff changeset
   148
  CodeHeap(const char* name, const int code_blob_type);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  // Heap extents
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 23214
diff changeset
   151
  bool  reserve(ReservedSpace rs, size_t committed_size, size_t segment_size);
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 22234
diff changeset
   152
  bool  expand_by(size_t size);                  // expands committed memory by size
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  // Memory allocation
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 26942
diff changeset
   155
  void* allocate (size_t size); // Allocate 'size' bytes in the code cache or return NULL
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 26942
diff changeset
   156
  void  deallocate(void* p);    // Deallocate memory
47688
3d1e3786d66e 8166317: InterpreterCodeSize should be computed
simonis
parents: 47216
diff changeset
   157
  // Free the tail of segments allocated by the last call to 'allocate()' which exceed 'used_size'.
3d1e3786d66e 8166317: InterpreterCodeSize should be computed
simonis
parents: 47216
diff changeset
   158
  // ATTENTION: this is only safe to use if there was no other call to 'allocate()' after
3d1e3786d66e 8166317: InterpreterCodeSize should be computed
simonis
parents: 47216
diff changeset
   159
  //            'p' was allocated. Only intended for freeing memory which would be otherwise
3d1e3786d66e 8166317: InterpreterCodeSize should be computed
simonis
parents: 47216
diff changeset
   160
  //            wasted after the interpreter generation because we don't know the interpreter size
3d1e3786d66e 8166317: InterpreterCodeSize should be computed
simonis
parents: 47216
diff changeset
   161
  //            beforehand and we also can't easily relocate the interpreter to a new location.
3d1e3786d66e 8166317: InterpreterCodeSize should be computed
simonis
parents: 47216
diff changeset
   162
  void  deallocate_tail(void* p, size_t used_size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
59145
ea044aedc2b6 8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents: 54943
diff changeset
   164
  // Boundaries of committed space.
ea044aedc2b6 8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents: 54943
diff changeset
   165
  char* low()  const                             { return _memory.low(); }
ea044aedc2b6 8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents: 54943
diff changeset
   166
  char* high() const                             { return _memory.high(); }
ea044aedc2b6 8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents: 54943
diff changeset
   167
  // Boundaries of reserved space.
46647
634dc786bf96 8183573: Refactor CodeHeap and AOTCodeHeap to devirtualize hot methods
redestad
parents: 43945
diff changeset
   168
  char* low_boundary() const                     { return _memory.low_boundary(); }
17016
78b1c3670525 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 13963
diff changeset
   169
  char* high_boundary() const                    { return _memory.high_boundary(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
59145
ea044aedc2b6 8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents: 54943
diff changeset
   171
  // Containment means "contained in committed space".
ea044aedc2b6 8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents: 54943
diff changeset
   172
  bool contains(const void* p) const             { return low() <= p && p < high(); }
47768
3d1d05c9b6cd 8187091: ReturnBlobToWrongHeapTest fails because of problems in CodeHeap::contains_blob()
simonis
parents: 47688
diff changeset
   173
  bool contains_blob(const CodeBlob* blob) const {
3d1d05c9b6cd 8187091: ReturnBlobToWrongHeapTest fails because of problems in CodeHeap::contains_blob()
simonis
parents: 47688
diff changeset
   174
    // AOT CodeBlobs (i.e. AOTCompiledMethod) objects aren't allocated in the AOTCodeHeap but on the C-Heap.
3d1d05c9b6cd 8187091: ReturnBlobToWrongHeapTest fails because of problems in CodeHeap::contains_blob()
simonis
parents: 47688
diff changeset
   175
    // Only the code they are pointing to is located in the AOTCodeHeap. All other CodeBlobs are allocated
3d1d05c9b6cd 8187091: ReturnBlobToWrongHeapTest fails because of problems in CodeHeap::contains_blob()
simonis
parents: 47688
diff changeset
   176
    // directly in their corresponding CodeHeap with their code appended to the actual C++ object.
3d1d05c9b6cd 8187091: ReturnBlobToWrongHeapTest fails because of problems in CodeHeap::contains_blob()
simonis
parents: 47688
diff changeset
   177
    // So all CodeBlobs except AOTCompiledMethod are continuous in memory with their data and code while
3d1d05c9b6cd 8187091: ReturnBlobToWrongHeapTest fails because of problems in CodeHeap::contains_blob()
simonis
parents: 47688
diff changeset
   178
    // AOTCompiledMethod and their code/data is distributed in the C-Heap. This means we can use the
3d1d05c9b6cd 8187091: ReturnBlobToWrongHeapTest fails because of problems in CodeHeap::contains_blob()
simonis
parents: 47688
diff changeset
   179
    // address of a CodeBlob object in order to locate it in its heap while we have to use the address
3d1d05c9b6cd 8187091: ReturnBlobToWrongHeapTest fails because of problems in CodeHeap::contains_blob()
simonis
parents: 47688
diff changeset
   180
    // of the actual code an AOTCompiledMethod object is pointing to in order to locate it.
3d1d05c9b6cd 8187091: ReturnBlobToWrongHeapTest fails because of problems in CodeHeap::contains_blob()
simonis
parents: 47688
diff changeset
   181
    // Notice that for an ordinary CodeBlob with code size zero, code_begin() may point beyond the object!
3d1d05c9b6cd 8187091: ReturnBlobToWrongHeapTest fails because of problems in CodeHeap::contains_blob()
simonis
parents: 47688
diff changeset
   182
    const void* start = AOT_ONLY( (code_blob_type() == CodeBlobType::AOT) ? blob->code_begin() : ) (void*)blob;
3d1d05c9b6cd 8187091: ReturnBlobToWrongHeapTest fails because of problems in CodeHeap::contains_blob()
simonis
parents: 47688
diff changeset
   183
    return contains(start);
3d1d05c9b6cd 8187091: ReturnBlobToWrongHeapTest fails because of problems in CodeHeap::contains_blob()
simonis
parents: 47688
diff changeset
   184
  }
43945
e7f2e49d2274 8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents: 42664
diff changeset
   185
31620
53be635ad49c 8087333: Optionally Pre-Generate the HotSpot Template Interpreter
bdelsart
parents: 30291
diff changeset
   186
  virtual void* find_start(void* p)     const;   // returns the block containing p or NULL
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 34158
diff changeset
   187
  virtual CodeBlob* find_blob_unsafe(void* start) const;
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   188
  size_t alignment_unit()       const;           // alignment of any block
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   189
  size_t alignment_offset()     const;           // offset of first byte of any block, within the enclosing alignment unit
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   190
  static size_t header_size();                   // returns the header size for each heap block
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
49611
973c9504178e 8198691: CodeHeap State Analytics
lucy
parents: 49364
diff changeset
   192
  size_t segment_size()         const { return _segment_size; }  // for CodeHeapState
973c9504178e 8198691: CodeHeap State Analytics
lucy
parents: 49364
diff changeset
   193
  HeapBlock* first_block() const;                                // for CodeHeapState
973c9504178e 8198691: CodeHeap State Analytics
lucy
parents: 49364
diff changeset
   194
  HeapBlock* next_block(HeapBlock* b) const;                     // for CodeHeapState
54943
6cbb5c2255e3 8223444: Improve CodeHeap Free Space Management
lucy
parents: 53244
diff changeset
   195
  HeapBlock* split_block(HeapBlock* b, size_t split_seg);        // split one block into two
49611
973c9504178e 8198691: CodeHeap State Analytics
lucy
parents: 49364
diff changeset
   196
973c9504178e 8198691: CodeHeap State Analytics
lucy
parents: 49364
diff changeset
   197
  FreeBlock* freelist()         const { return _freelist; }      // for CodeHeapState
973c9504178e 8198691: CodeHeap State Analytics
lucy
parents: 49364
diff changeset
   198
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   199
  size_t allocated_in_freelist() const           { return _freelist_segments * CodeCacheSegmentSize; }
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   200
  int    freelist_length()       const           { return _freelist_length; } // number of elements in the freelist
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  // returns the first block or NULL
31620
53be635ad49c 8087333: Optionally Pre-Generate the HotSpot Template Interpreter
bdelsart
parents: 30291
diff changeset
   203
  virtual void* first() const                    { return next_used(first_block()); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  // returns the next block given a block p or NULL
31620
53be635ad49c 8087333: Optionally Pre-Generate the HotSpot Template Interpreter
bdelsart
parents: 30291
diff changeset
   205
  virtual void* next(void* p) const              { return next_used(next_block(block_start(p))); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  // Statistics
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  size_t capacity() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  size_t max_capacity() const;
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   210
  int    allocated_segments() const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  size_t allocated_capacity() const;
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 23214
diff changeset
   212
  size_t max_allocated_capacity() const          { return _max_allocated_capacity; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  size_t unallocated_capacity() const            { return max_capacity() - allocated_capacity(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 23214
diff changeset
   215
  // Returns true if the CodeHeap contains CodeBlobs of the given type
26942
fa5ea7ff078d 8059390: code cache fills up for bigapps/Weblogic+medrec/nowarnings
zmajo
parents: 26796
diff changeset
   216
  bool accepts(int code_blob_type) const         { return (_code_blob_type == CodeBlobType::All) ||
fa5ea7ff078d 8059390: code cache fills up for bigapps/Weblogic+medrec/nowarnings
zmajo
parents: 26796
diff changeset
   217
                                                          (_code_blob_type == code_blob_type); }
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 23214
diff changeset
   218
  int code_blob_type() const                     { return _code_blob_type; }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 23214
diff changeset
   219
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 23214
diff changeset
   220
  // Debugging / Profiling
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 23214
diff changeset
   221
  const char* name() const                       { return _name; }
34158
1f8d643b02d5 8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents: 31620
diff changeset
   222
  int         blob_count()                       { return _blob_count; }
1f8d643b02d5 8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents: 31620
diff changeset
   223
  int         nmethod_count()                    { return _nmethod_count; }
1f8d643b02d5 8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents: 31620
diff changeset
   224
  void    set_nmethod_count(int count)           {        _nmethod_count = count; }
1f8d643b02d5 8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents: 31620
diff changeset
   225
  int         adapter_count()                    { return _adapter_count; }
1f8d643b02d5 8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents: 31620
diff changeset
   226
  void    set_adapter_count(int count)           {        _adapter_count = count; }
1f8d643b02d5 8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents: 31620
diff changeset
   227
  int         full_count()                       { return _full_count; }
1f8d643b02d5 8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents: 31620
diff changeset
   228
  void        report_full()                      {        _full_count++; }
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 23214
diff changeset
   229
17016
78b1c3670525 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 13963
diff changeset
   230
private:
78b1c3670525 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 13963
diff changeset
   231
  size_t heap_unallocated_capacity() const;
59145
ea044aedc2b6 8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents: 54943
diff changeset
   232
  int defrag_segmap(bool do_defrag);
ea044aedc2b6 8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents: 54943
diff changeset
   233
  int segmap_hops(size_t beg, size_t end);
17016
78b1c3670525 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 13963
diff changeset
   234
78b1c3670525 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 13963
diff changeset
   235
public:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  // Debugging
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   237
  void verify() PRODUCT_RETURN;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  void print()  PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
   240
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49611
diff changeset
   241
#endif // SHARE_MEMORY_HEAP_HPP