1 /* |
1 /* |
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
47 friend class VMStructs; |
47 friend class VMStructs; |
48 debug_only(int _nesting;) // current # of nested ResourceMarks |
48 debug_only(int _nesting;) // current # of nested ResourceMarks |
49 debug_only(static int _warned;) // to suppress multiple warnings |
49 debug_only(static int _warned;) // to suppress multiple warnings |
50 |
50 |
51 public: |
51 public: |
52 ResourceArea() { |
52 ResourceArea() : Arena(mtThread) { |
53 debug_only(_nesting = 0;) |
53 debug_only(_nesting = 0;) |
54 } |
54 } |
55 |
55 |
56 ResourceArea(size_t init_size) : Arena(init_size) { |
56 ResourceArea(size_t init_size) : Arena(mtThread, init_size) { |
57 debug_only(_nesting = 0;); |
57 debug_only(_nesting = 0;); |
58 } |
58 } |
59 |
59 |
60 char* allocate_bytes(size_t size, AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) { |
60 char* allocate_bytes(size_t size, AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) { |
61 #ifdef ASSERT |
61 #ifdef ASSERT |
62 if (_nesting < 1 && !_warned++) |
62 if (_nesting < 1 && !_warned++) |
63 fatal("memory leak: allocating without ResourceMark"); |
63 fatal("memory leak: allocating without ResourceMark"); |
64 if (UseMallocOnly) { |
64 if (UseMallocOnly) { |
65 // use malloc, but save pointer in res. area for later freeing |
65 // use malloc, but save pointer in res. area for later freeing |
66 char** save = (char**)internal_malloc_4(sizeof(char*)); |
66 char** save = (char**)internal_malloc_4(sizeof(char*)); |
67 return (*save = (char*)os::malloc(size, mtThread)); |
67 return (*save = (char*)os::malloc(size, mtThread, CURRENT_PC)); |
68 } |
68 } |
69 #endif |
69 #endif |
70 return (char*)Amalloc(size, alloc_failmode); |
70 return (char*)Amalloc(size, alloc_failmode); |
71 } |
71 } |
72 |
72 |