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 *
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:
59 ResourceArea() {
60 debug_only(_nesting = 0;)
61 }
62
63 ResourceArea(size_t init_size) : Arena(init_size) {
64 debug_only(_nesting = 0;);
65 }
66
67 char* allocate_bytes(size_t size) {
68 #ifdef ASSERT
69 if (_nesting < 1 && !_warned++)
70 fatal("memory leak: allocating without ResourceMark");
71 if (UseMallocOnly) {
72 // use malloc, but save pointer in res. area for later freeing
73 char** save = (char**)internal_malloc_4(sizeof(char*));
74 return (*save = (char*)os::malloc(size));
|
1 /*
2 * Copyright (c) 1997, 2011, 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 *
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 friend class VMStructs;
56 debug_only(int _nesting;) // current # of nested ResourceMarks
57 debug_only(static int _warned;) // to suppress multiple warnings
58
59 public:
60 ResourceArea() {
61 debug_only(_nesting = 0;)
62 }
63
64 ResourceArea(size_t init_size) : Arena(init_size) {
65 debug_only(_nesting = 0;);
66 }
67
68 char* allocate_bytes(size_t size) {
69 #ifdef ASSERT
70 if (_nesting < 1 && !_warned++)
71 fatal("memory leak: allocating without ResourceMark");
72 if (UseMallocOnly) {
73 // use malloc, but save pointer in res. area for later freeing
74 char** save = (char**)internal_malloc_4(sizeof(char*));
75 return (*save = (char*)os::malloc(size));
|