1 /*
2 * Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 // The resource area holds temporary data structures in the VM.
26 // The actual allocation areas are thread local. Typical usage:
27 //
28 // ...
29 // {
30 // ResourceMark rm;
31 // int foo[] = NEW_RESOURCE_ARRAY(int, 64);
32 // ...
33 // }
34 // ...
35
36 //------------------------------ResourceArea-----------------------------------
37 // A ResourceArea is an Arena that supports safe usage of ResourceMark.
38 class ResourceArea: public Arena {
39 friend class ResourceMark;
40 friend class DeoptResourceMark;
41 debug_only(int _nesting;) // current # of nested ResourceMarks
42 debug_only(static int _warned;) // to suppress multiple warnings
43
44 public:
207 _area->_chunk = _chunk; // Roll back arena to saved chunk
208 _area->_hwm = _hwm;
209 _area->_max = _max;
210
211 // clear out this chunk (to detect allocation bugs)
212 if (ZapResourceArea) memset(_hwm, badResourceValue, _max - _hwm);
213 _area->set_size_in_bytes(size_in_bytes());
214 }
215
216 ~DeoptResourceMark() {
217 assert( _area->_nesting > 0, "must stack allocate RMs" );
218 debug_only(_area->_nesting--;)
219 reset_to_mark();
220 }
221
222
223 private:
224 void free_malloced_objects() PRODUCT_RETURN;
225 size_t size_in_bytes() NOT_PRODUCT({ return _size_in_bytes; }) PRODUCT_RETURN0;
226 };
|
1 /*
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_MEMORY_RESOURCEAREA_HPP
26 #define SHARE_VM_MEMORY_RESOURCEAREA_HPP
27
28 #include "memory/allocation.hpp"
29 #ifdef TARGET_OS_FAMILY_linux
30 # include "thread_linux.inline.hpp"
31 #endif
32 #ifdef TARGET_OS_FAMILY_solaris
33 # include "thread_solaris.inline.hpp"
34 #endif
35 #ifdef TARGET_OS_FAMILY_windows
36 # include "thread_windows.inline.hpp"
37 #endif
38
39 // The resource area holds temporary data structures in the VM.
40 // The actual allocation areas are thread local. Typical usage:
41 //
42 // ...
43 // {
44 // ResourceMark rm;
45 // int foo[] = NEW_RESOURCE_ARRAY(int, 64);
46 // ...
47 // }
48 // ...
49
50 //------------------------------ResourceArea-----------------------------------
51 // A ResourceArea is an Arena that supports safe usage of ResourceMark.
52 class ResourceArea: public Arena {
53 friend class ResourceMark;
54 friend class DeoptResourceMark;
55 debug_only(int _nesting;) // current # of nested ResourceMarks
56 debug_only(static int _warned;) // to suppress multiple warnings
57
58 public:
221 _area->_chunk = _chunk; // Roll back arena to saved chunk
222 _area->_hwm = _hwm;
223 _area->_max = _max;
224
225 // clear out this chunk (to detect allocation bugs)
226 if (ZapResourceArea) memset(_hwm, badResourceValue, _max - _hwm);
227 _area->set_size_in_bytes(size_in_bytes());
228 }
229
230 ~DeoptResourceMark() {
231 assert( _area->_nesting > 0, "must stack allocate RMs" );
232 debug_only(_area->_nesting--;)
233 reset_to_mark();
234 }
235
236
237 private:
238 void free_malloced_objects() PRODUCT_RETURN;
239 size_t size_in_bytes() NOT_PRODUCT({ return _size_in_bytes; }) PRODUCT_RETURN0;
240 };
241
242 #endif // SHARE_VM_MEMORY_RESOURCEAREA_HPP
|