src/share/vm/adlc/arena.hpp

Tue, 20 Feb 2018 07:10:42 -0500

author
lfoltan
date
Tue, 20 Feb 2018 07:10:42 -0500
changeset 9323
6688d6c6a225
parent 5614
9758d9f36299
child 9448
73d689add964
permissions
-rw-r--r--

8196880: VS2017 Addition of Global Delete Operator with Size Parameter Conflicts with Arena's Chunk Provided One
Summary: Add a private ordinary operator delete declaration within class Chunk.
Reviewed-by: coleenp, stuefe
Contributed-by: kim.barrett@oracle.com, lois.foltan@oracle.com

duke@435 1 /*
lfoltan@9323 2 * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_ADLC_ARENA_HPP
stefank@2314 26 #define SHARE_VM_ADLC_ARENA_HPP
stefank@2314 27
duke@435 28 // All classes in the virtual machine must be subclassed
duke@435 29 // by one of the following allocation classes:
duke@435 30 //
duke@435 31 //
duke@435 32 // For objects allocated in the C-heap (managed by: free & malloc).
duke@435 33 // - CHeapObj
duke@435 34 //
duke@435 35 //
duke@435 36 // For embedded objects.
duke@435 37 // - ValueObj
duke@435 38 //
duke@435 39 // For classes used as name spaces.
duke@435 40 // - AllStatic
duke@435 41 //
duke@435 42
duke@435 43 class CHeapObj {
duke@435 44 public:
coleenp@5614 45 void* operator new(size_t size) throw();
duke@435 46 void operator delete(void* p);
duke@435 47 void* new_array(size_t size);
duke@435 48 };
duke@435 49
duke@435 50
duke@435 51 // Base class for objects used as value objects.
duke@435 52 // Calling new or delete will result in fatal error.
duke@435 53
duke@435 54 class ValueObj {
duke@435 55 public:
coleenp@5614 56 void* operator new(size_t size) throw();
duke@435 57 void operator delete(void* p);
duke@435 58 };
duke@435 59
duke@435 60 // Base class for classes that constitute name spaces.
duke@435 61
duke@435 62 class AllStatic {
duke@435 63 public:
coleenp@5614 64 void* operator new(size_t size) throw();
duke@435 65 void operator delete(void* p);
duke@435 66 };
duke@435 67
duke@435 68
duke@435 69 //------------------------------Chunk------------------------------------------
duke@435 70 // Linked list of raw memory chunks
duke@435 71 class Chunk: public CHeapObj {
lfoltan@9323 72 private:
lfoltan@9323 73 // This ordinary operator delete is needed even though not used, so the
lfoltan@9323 74 // below two-argument operator delete will be treated as a placement
lfoltan@9323 75 // delete rather than an ordinary sized delete; see C++14 3.7.4.2/p2.
lfoltan@9323 76 void operator delete(void* p);
duke@435 77 public:
coleenp@5614 78 void* operator new(size_t size, size_t length) throw();
duke@435 79 void operator delete(void* p, size_t length);
duke@435 80 Chunk(size_t length);
duke@435 81
duke@435 82 enum {
duke@435 83 init_size = 1*1024, // Size of first chunk
duke@435 84 size = 32*1024 // Default size of an Arena chunk (following the first)
duke@435 85 };
duke@435 86 Chunk* _next; // Next Chunk in list
duke@435 87 size_t _len; // Size of this Chunk
duke@435 88
duke@435 89 void chop(); // Chop this chunk
duke@435 90 void next_chop(); // Chop next chunk
duke@435 91
duke@435 92 // Boundaries of data area (possibly unused)
duke@435 93 char* bottom() const { return ((char*) this) + sizeof(Chunk); }
duke@435 94 char* top() const { return bottom() + _len; }
duke@435 95 };
duke@435 96
duke@435 97
duke@435 98 //------------------------------Arena------------------------------------------
duke@435 99 // Fast allocation of memory
duke@435 100 class Arena: public CHeapObj {
duke@435 101 protected:
duke@435 102 friend class ResourceMark;
duke@435 103 friend class HandleMark;
duke@435 104 friend class NoHandleMark;
duke@435 105 Chunk *_first; // First chunk
duke@435 106 Chunk *_chunk; // current chunk
duke@435 107 char *_hwm, *_max; // High water mark and max in current chunk
duke@435 108 void* grow(size_t x); // Get a new Chunk of at least size x
duke@435 109 size_t _size_in_bytes; // Size of arena (used for memory usage tracing)
duke@435 110 public:
duke@435 111 Arena();
duke@435 112 Arena(size_t init_size);
duke@435 113 Arena(Arena *old);
duke@435 114 ~Arena() { _first->chop(); }
duke@435 115 char* hwm() const { return _hwm; }
duke@435 116
duke@435 117 // Fast allocate in the arena. Common case is: pointer test + increment.
duke@435 118 void* Amalloc(size_t x) {
duke@435 119 #ifdef _LP64
duke@435 120 x = (x + (8-1)) & ((unsigned)(-8));
duke@435 121 #else
duke@435 122 x = (x + (4-1)) & ((unsigned)(-4));
duke@435 123 #endif
duke@435 124 if (_hwm + x > _max) {
duke@435 125 return grow(x);
duke@435 126 } else {
duke@435 127 char *old = _hwm;
duke@435 128 _hwm += x;
duke@435 129 return old;
duke@435 130 }
duke@435 131 }
duke@435 132 // Further assume size is padded out to words
duke@435 133 // Warning: in LP64, Amalloc_4 is really Amalloc_8
duke@435 134 void *Amalloc_4(size_t x) {
duke@435 135 assert( (x&(sizeof(char*)-1)) == 0, "misaligned size" );
duke@435 136 if (_hwm + x > _max) {
duke@435 137 return grow(x);
duke@435 138 } else {
duke@435 139 char *old = _hwm;
duke@435 140 _hwm += x;
duke@435 141 return old;
duke@435 142 }
duke@435 143 }
duke@435 144
duke@435 145 // Fast delete in area. Common case is: NOP (except for storage reclaimed)
duke@435 146 void Afree(void *ptr, size_t size) {
duke@435 147 if (((char*)ptr) + size == _hwm) _hwm = (char*)ptr;
duke@435 148 }
duke@435 149
duke@435 150 void *Acalloc( size_t items, size_t x );
duke@435 151 void *Arealloc( void *old_ptr, size_t old_size, size_t new_size );
duke@435 152
duke@435 153 // Reset this Arena to empty, and return this Arenas guts in a new Arena.
duke@435 154 Arena *reset(void);
duke@435 155
duke@435 156 // Determine if pointer belongs to this Arena or not.
duke@435 157 bool contains( const void *ptr ) const;
duke@435 158
duke@435 159 // Total of all chunks in use (not thread-safe)
duke@435 160 size_t used() const;
duke@435 161
duke@435 162 // Total # of bytes used
duke@435 163 size_t size_in_bytes() const { return _size_in_bytes; }
duke@435 164 void set_size_in_bytes(size_t size) { _size_in_bytes = size; }
duke@435 165 };
stefank@2314 166
stefank@2314 167 #endif // SHARE_VM_ADLC_ARENA_HPP

mercurial