< prev index next >

src/share/vm/memory/resourceArea.hpp

Print this page


   1 /*
   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.
   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  *


 104   }
 105  public:
 106 
 107 #ifndef ASSERT
 108   ResourceMark(Thread *thread) {
 109     assert(thread == Thread::current(), "not the current thread");
 110     initialize(thread);
 111   }
 112 #else
 113   ResourceMark(Thread *thread);
 114 #endif // ASSERT
 115 
 116   ResourceMark()               { initialize(Thread::current()); }
 117 
 118   ResourceMark( ResourceArea *r ) :
 119     _area(r), _chunk(r->_chunk), _hwm(r->_hwm), _max(r->_max) {
 120     _size_in_bytes = r->_size_in_bytes;
 121     debug_only(_area->_nesting++;)
 122     assert( _area->_nesting > 0, "must stack allocate RMs" );
 123 #ifdef ASSERT
 124     Thread* thread = ThreadLocalStorage::thread();
 125     if (thread != NULL) {
 126       _thread = thread;
 127       _previous_resource_mark = thread->current_resource_mark();
 128       thread->set_current_resource_mark(this);
 129     } else {
 130       _thread = NULL;
 131       _previous_resource_mark = NULL;
 132     }
 133 #endif // ASSERT
 134   }
 135 
 136   void reset_to_mark() {
 137     if (UseMallocOnly) free_malloced_objects();
 138 
 139     if( _chunk->next() ) {       // Delete later chunks
 140       // reset arena size before delete chunks. Otherwise, the total
 141       // arena size could exceed total chunk size
 142       assert(_area->size_in_bytes() > size_in_bytes(), "Sanity check");
 143       _area->set_size_in_bytes(size_in_bytes());
 144       _chunk->next_chop();


   1 /*
   2  * Copyright (c) 1997, 2015, 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  *


 104   }
 105  public:
 106 
 107 #ifndef ASSERT
 108   ResourceMark(Thread *thread) {
 109     assert(thread == Thread::current(), "not the current thread");
 110     initialize(thread);
 111   }
 112 #else
 113   ResourceMark(Thread *thread);
 114 #endif // ASSERT
 115 
 116   ResourceMark()               { initialize(Thread::current()); }
 117 
 118   ResourceMark( ResourceArea *r ) :
 119     _area(r), _chunk(r->_chunk), _hwm(r->_hwm), _max(r->_max) {
 120     _size_in_bytes = r->_size_in_bytes;
 121     debug_only(_area->_nesting++;)
 122     assert( _area->_nesting > 0, "must stack allocate RMs" );
 123 #ifdef ASSERT
 124     Thread* thread = Thread::current_or_null();
 125     if (thread != NULL) {
 126       _thread = thread;
 127       _previous_resource_mark = thread->current_resource_mark();
 128       thread->set_current_resource_mark(this);
 129     } else {
 130       _thread = NULL;
 131       _previous_resource_mark = NULL;
 132     }
 133 #endif // ASSERT
 134   }
 135 
 136   void reset_to_mark() {
 137     if (UseMallocOnly) free_malloced_objects();
 138 
 139     if( _chunk->next() ) {       // Delete later chunks
 140       // reset arena size before delete chunks. Otherwise, the total
 141       // arena size could exceed total chunk size
 142       assert(_area->size_in_bytes() > size_in_bytes(), "Sanity check");
 143       _area->set_size_in_bytes(size_in_bytes());
 144       _chunk->next_chop();


< prev index next >