hotspot/src/share/vm/memory/resourceArea.hpp
changeset 25946 1572c9f03fb9
parent 22551 9bf46d16dcc6
child 34633 2a6c7c7b30a7
equal deleted inserted replaced
25902:7e9ffb1fe1df 25946:1572c9f03fb9
     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