annotate src/share/vm/adlc/arena.cpp @ 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
a61af66fc99e Initial load
duke
parents:
diff changeset
25 #include "adlc.hpp"
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 void* Chunk::operator new(size_t requested_size, size_t length) {
a61af66fc99e Initial load
duke
parents:
diff changeset
28 return CHeapObj::operator new(requested_size + length);
a61af66fc99e Initial load
duke
parents:
diff changeset
29 }
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 void Chunk::operator delete(void* p, size_t length) {
a61af66fc99e Initial load
duke
parents:
diff changeset
32 CHeapObj::operator delete(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
33 }
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 Chunk::Chunk(size_t length) {
a61af66fc99e Initial load
duke
parents:
diff changeset
36 _next = NULL; // Chain on the linked list
a61af66fc99e Initial load
duke
parents:
diff changeset
37 _len = length; // Save actual size
a61af66fc99e Initial load
duke
parents:
diff changeset
38 }
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 //------------------------------chop-------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
41 void Chunk::chop() {
a61af66fc99e Initial load
duke
parents:
diff changeset
42 Chunk *k = this;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 while( k ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
44 Chunk *tmp = k->_next;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // clear out this chunk (to detect allocation bugs)
a61af66fc99e Initial load
duke
parents:
diff changeset
46 memset(k, 0xBAADBABE, k->_len);
a61af66fc99e Initial load
duke
parents:
diff changeset
47 free(k); // Free chunk (was malloc'd)
a61af66fc99e Initial load
duke
parents:
diff changeset
48 k = tmp;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 }
a61af66fc99e Initial load
duke
parents:
diff changeset
50 }
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 void Chunk::next_chop() {
a61af66fc99e Initial load
duke
parents:
diff changeset
53 _next->chop();
a61af66fc99e Initial load
duke
parents:
diff changeset
54 _next = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 }
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 //------------------------------Arena------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
58 Arena::Arena( size_t init_size ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
59 init_size = (init_size+3) & ~3;
a61af66fc99e Initial load
duke
parents:
diff changeset
60 _first = _chunk = new (init_size) Chunk(init_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
61 _hwm = _chunk->bottom(); // Save the cached hwm, max
a61af66fc99e Initial load
duke
parents:
diff changeset
62 _max = _chunk->top();
a61af66fc99e Initial load
duke
parents:
diff changeset
63 set_size_in_bytes(init_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
64 }
a61af66fc99e Initial load
duke
parents:
diff changeset
65
a61af66fc99e Initial load
duke
parents:
diff changeset
66 Arena::Arena() {
a61af66fc99e Initial load
duke
parents:
diff changeset
67 _first = _chunk = new (Chunk::init_size) Chunk(Chunk::init_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
68 _hwm = _chunk->bottom(); // Save the cached hwm, max
a61af66fc99e Initial load
duke
parents:
diff changeset
69 _max = _chunk->top();
a61af66fc99e Initial load
duke
parents:
diff changeset
70 set_size_in_bytes(Chunk::init_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
71 }
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73 Arena::Arena( Arena *a )
a61af66fc99e Initial load
duke
parents:
diff changeset
74 : _chunk(a->_chunk), _hwm(a->_hwm), _max(a->_max), _first(a->_first) {
a61af66fc99e Initial load
duke
parents:
diff changeset
75 set_size_in_bytes(a->size_in_bytes());
a61af66fc99e Initial load
duke
parents:
diff changeset
76 }
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 //------------------------------used-------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
79 // Total of all Chunks in arena
a61af66fc99e Initial load
duke
parents:
diff changeset
80 size_t Arena::used() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
81 size_t sum = _chunk->_len - (_max-_hwm); // Size leftover in this Chunk
a61af66fc99e Initial load
duke
parents:
diff changeset
82 register Chunk *k = _first;
a61af66fc99e Initial load
duke
parents:
diff changeset
83 while( k != _chunk) { // Whilst have Chunks in a row
a61af66fc99e Initial load
duke
parents:
diff changeset
84 sum += k->_len; // Total size of this Chunk
a61af66fc99e Initial load
duke
parents:
diff changeset
85 k = k->_next; // Bump along to next Chunk
a61af66fc99e Initial load
duke
parents:
diff changeset
86 }
a61af66fc99e Initial load
duke
parents:
diff changeset
87 return sum; // Return total consumed space.
a61af66fc99e Initial load
duke
parents:
diff changeset
88 }
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 //------------------------------grow-------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
91 // Grow a new Chunk
a61af66fc99e Initial load
duke
parents:
diff changeset
92 void* Arena::grow( size_t x ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
93 // Get minimal required size. Either real big, or even bigger for giant objs
a61af66fc99e Initial load
duke
parents:
diff changeset
94 size_t len = max(x, Chunk::size);
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 register Chunk *k = _chunk; // Get filled-up chunk address
a61af66fc99e Initial load
duke
parents:
diff changeset
97 _chunk = new (len) Chunk(len);
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 if( k ) k->_next = _chunk; // Append new chunk to end of linked list
a61af66fc99e Initial load
duke
parents:
diff changeset
100 else _first = _chunk;
a61af66fc99e Initial load
duke
parents:
diff changeset
101 _hwm = _chunk->bottom(); // Save the cached hwm, max
a61af66fc99e Initial load
duke
parents:
diff changeset
102 _max = _chunk->top();
a61af66fc99e Initial load
duke
parents:
diff changeset
103 set_size_in_bytes(size_in_bytes() + len);
a61af66fc99e Initial load
duke
parents:
diff changeset
104 void* result = _hwm;
a61af66fc99e Initial load
duke
parents:
diff changeset
105 _hwm += x;
a61af66fc99e Initial load
duke
parents:
diff changeset
106 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
107 }
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109 //------------------------------calloc-----------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
110 // Allocate zeroed storage in Arena
a61af66fc99e Initial load
duke
parents:
diff changeset
111 void *Arena::Acalloc( size_t items, size_t x ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 size_t z = items*x; // Total size needed
a61af66fc99e Initial load
duke
parents:
diff changeset
113 void *ptr = Amalloc(z); // Get space
a61af66fc99e Initial load
duke
parents:
diff changeset
114 memset( ptr, 0, z ); // Zap space
a61af66fc99e Initial load
duke
parents:
diff changeset
115 return ptr; // Return space
a61af66fc99e Initial load
duke
parents:
diff changeset
116 }
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 //------------------------------realloc----------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // Reallocate storage in Arena.
a61af66fc99e Initial load
duke
parents:
diff changeset
120 void *Arena::Arealloc( void *old_ptr, size_t old_size, size_t new_size ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 char *c_old = (char*)old_ptr; // Handy name
a61af66fc99e Initial load
duke
parents:
diff changeset
122 // Stupid fast special case
a61af66fc99e Initial load
duke
parents:
diff changeset
123 if( new_size <= old_size ) { // Shrink in-place
a61af66fc99e Initial load
duke
parents:
diff changeset
124 if( c_old+old_size == _hwm) // Attempt to free the excess bytes
a61af66fc99e Initial load
duke
parents:
diff changeset
125 _hwm = c_old+new_size; // Adjust hwm
a61af66fc99e Initial load
duke
parents:
diff changeset
126 return c_old;
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 // See if we can resize in-place
a61af66fc99e Initial load
duke
parents:
diff changeset
130 if( (c_old+old_size == _hwm) && // Adjusting recent thing
a61af66fc99e Initial load
duke
parents:
diff changeset
131 (c_old+new_size <= _max) ) { // Still fits where it sits
a61af66fc99e Initial load
duke
parents:
diff changeset
132 _hwm = c_old+new_size; // Adjust hwm
a61af66fc99e Initial load
duke
parents:
diff changeset
133 return c_old; // Return old pointer
a61af66fc99e Initial load
duke
parents:
diff changeset
134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 // Oops, got to relocate guts
a61af66fc99e Initial load
duke
parents:
diff changeset
137 void *new_ptr = Amalloc(new_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
138 memcpy( new_ptr, c_old, old_size );
a61af66fc99e Initial load
duke
parents:
diff changeset
139 Afree(c_old,old_size); // Mostly done to keep stats accurate
a61af66fc99e Initial load
duke
parents:
diff changeset
140 return new_ptr;
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 //------------------------------reset------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
144 // Reset this Arena to empty, and return this Arenas guts in a new Arena.
a61af66fc99e Initial load
duke
parents:
diff changeset
145 Arena *Arena::reset(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 Arena *a = new Arena(this); // New empty arena
a61af66fc99e Initial load
duke
parents:
diff changeset
147 _first = _chunk = NULL; // Normal, new-arena initialization
a61af66fc99e Initial load
duke
parents:
diff changeset
148 _hwm = _max = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
149 return a; // Return Arena with guts
a61af66fc99e Initial load
duke
parents:
diff changeset
150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
151
a61af66fc99e Initial load
duke
parents:
diff changeset
152 //------------------------------contains---------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
153 // Determine if pointer belongs to this Arena or not.
a61af66fc99e Initial load
duke
parents:
diff changeset
154 bool Arena::contains( const void *ptr ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
155 if( (void*)_chunk->bottom() <= ptr && ptr < (void*)_hwm )
a61af66fc99e Initial load
duke
parents:
diff changeset
156 return true; // Check for in this chunk
a61af66fc99e Initial load
duke
parents:
diff changeset
157 for( Chunk *c = _first; c; c = c->_next )
a61af66fc99e Initial load
duke
parents:
diff changeset
158 if( (void*)c->bottom() <= ptr && ptr < (void*)c->top())
a61af66fc99e Initial load
duke
parents:
diff changeset
159 return true; // Check for every chunk in Arena
a61af66fc99e Initial load
duke
parents:
diff changeset
160 return false; // Not in any Chunk, so not in Arena
a61af66fc99e Initial load
duke
parents:
diff changeset
161 }
a61af66fc99e Initial load
duke
parents:
diff changeset
162
a61af66fc99e Initial load
duke
parents:
diff changeset
163 //-----------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
164 // CHeapObj
a61af66fc99e Initial load
duke
parents:
diff changeset
165
a61af66fc99e Initial load
duke
parents:
diff changeset
166 void* CHeapObj::operator new(size_t size){
a61af66fc99e Initial load
duke
parents:
diff changeset
167 return (void *) malloc(size);
a61af66fc99e Initial load
duke
parents:
diff changeset
168 }
a61af66fc99e Initial load
duke
parents:
diff changeset
169
a61af66fc99e Initial load
duke
parents:
diff changeset
170 void CHeapObj::operator delete(void* p){
a61af66fc99e Initial load
duke
parents:
diff changeset
171 free(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
172 }