annotate src/share/vm/adlc/arena.hpp @ 1972:f95d63e2154a

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