< prev index next >

src/hotspot/share/memory/metaspace/testHelpers.cpp

Print this page

  7  * under the terms of the GNU General Public License version 2 only, as
  8  * published by the Free Software Foundation.
  9  *
 10  * This code is distributed in the hope that it will be useful, but WITHOUT
 11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 13  * version 2 for more details (a copy is included in the LICENSE file that
 14  * accompanied this code).
 15  *
 16  * You should have received a copy of the GNU General Public License version
 17  * 2 along with this work; if not, write to the Free Software Foundation,
 18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 19  *
 20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 21  * or visit www.oracle.com if you need additional information or have any
 22  * questions.
 23  *
 24  */
 25 
 26 #include "precompiled.hpp"

 27 #include "memory/metaspace/metaspaceArena.hpp"
 28 #include "memory/metaspace/metaspaceArenaGrowthPolicy.hpp"
 29 #include "memory/metaspace/metaspaceContext.hpp"
 30 #include "memory/metaspace/testHelpers.hpp"
 31 #include "runtime/mutexLocker.hpp"
 32 #include "utilities/debug.hpp"
 33 #include "utilities/globalDefinitions.hpp"
 34 #include "utilities/ostream.hpp"
 35 
 36 namespace metaspace {
 37 
 38 ///// MetaspaceTestArena //////
 39 
 40 MetaspaceTestArena::MetaspaceTestArena(Mutex* lock, MetaspaceArena* arena) :
 41   _lock(lock),
 42   _arena(arena)
 43 {}
 44 
 45 MetaspaceTestArena::~MetaspaceTestArena() {
 46   delete _arena;

 79   }
 80 
 81 }
 82 
 83 MetaspaceTestContext::~MetaspaceTestContext() {
 84   DEBUG_ONLY(verify();)
 85   MutexLocker fcl(Metaspace_lock, Mutex::_no_safepoint_check_flag);
 86   delete _context;
 87   if (_rs.is_reserved()) {
 88     _rs.release();
 89   }
 90 }
 91 
 92 // Create an arena, feeding off this area.
 93 MetaspaceTestArena* MetaspaceTestContext::create_arena(Metaspace::MetaspaceType type) {
 94   const ArenaGrowthPolicy* growth_policy = ArenaGrowthPolicy::policy_for_space_type(type, false);
 95   Mutex* lock = new Mutex(Monitor::nosafepoint, "MetaspaceTestArea_lock");
 96   MetaspaceArena* arena = NULL;
 97   {
 98     MutexLocker ml(lock,  Mutex::_no_safepoint_check_flag);
 99     arena = new MetaspaceArena(_context->cm(), growth_policy, lock, &_used_words_counter, _name);

100   }
101   return new MetaspaceTestArena(lock, arena);
102 }
103 
104 void MetaspaceTestContext::purge_area() {
105   _context->cm()->purge();
106 }
107 
108 #ifdef ASSERT
109 void MetaspaceTestContext::verify() const {
110   if (_context != NULL) {
111     _context->verify();
112   }
113 }
114 #endif
115 
116 void MetaspaceTestContext::print_on(outputStream* st) const {
117   _context->print_on(st);
118 }
119 

  7  * under the terms of the GNU General Public License version 2 only, as
  8  * published by the Free Software Foundation.
  9  *
 10  * This code is distributed in the hope that it will be useful, but WITHOUT
 11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 13  * version 2 for more details (a copy is included in the LICENSE file that
 14  * accompanied this code).
 15  *
 16  * You should have received a copy of the GNU General Public License version
 17  * 2 along with this work; if not, write to the Free Software Foundation,
 18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 19  *
 20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 21  * or visit www.oracle.com if you need additional information or have any
 22  * questions.
 23  *
 24  */
 25 
 26 #include "precompiled.hpp"
 27 #include "memory/metaspace/metaspaceAlignment.hpp"
 28 #include "memory/metaspace/metaspaceArena.hpp"
 29 #include "memory/metaspace/metaspaceArenaGrowthPolicy.hpp"
 30 #include "memory/metaspace/metaspaceContext.hpp"
 31 #include "memory/metaspace/testHelpers.hpp"
 32 #include "runtime/mutexLocker.hpp"
 33 #include "utilities/debug.hpp"
 34 #include "utilities/globalDefinitions.hpp"
 35 #include "utilities/ostream.hpp"
 36 
 37 namespace metaspace {
 38 
 39 ///// MetaspaceTestArena //////
 40 
 41 MetaspaceTestArena::MetaspaceTestArena(Mutex* lock, MetaspaceArena* arena) :
 42   _lock(lock),
 43   _arena(arena)
 44 {}
 45 
 46 MetaspaceTestArena::~MetaspaceTestArena() {
 47   delete _arena;

 80   }
 81 
 82 }
 83 
 84 MetaspaceTestContext::~MetaspaceTestContext() {
 85   DEBUG_ONLY(verify();)
 86   MutexLocker fcl(Metaspace_lock, Mutex::_no_safepoint_check_flag);
 87   delete _context;
 88   if (_rs.is_reserved()) {
 89     _rs.release();
 90   }
 91 }
 92 
 93 // Create an arena, feeding off this area.
 94 MetaspaceTestArena* MetaspaceTestContext::create_arena(Metaspace::MetaspaceType type) {
 95   const ArenaGrowthPolicy* growth_policy = ArenaGrowthPolicy::policy_for_space_type(type, false);
 96   Mutex* lock = new Mutex(Monitor::nosafepoint, "MetaspaceTestArea_lock");
 97   MetaspaceArena* arena = NULL;
 98   {
 99     MutexLocker ml(lock,  Mutex::_no_safepoint_check_flag);
100     arena = new MetaspaceArena(_context->cm(), growth_policy, MetaspaceMinAlignmentWords,
101                                lock, &_used_words_counter, _name);
102   }
103   return new MetaspaceTestArena(lock, arena);
104 }
105 
106 void MetaspaceTestContext::purge_area() {
107   _context->cm()->purge();
108 }
109 
110 #ifdef ASSERT
111 void MetaspaceTestContext::verify() const {
112   if (_context != NULL) {
113     _context->verify();
114   }
115 }
116 #endif
117 
118 void MetaspaceTestContext::print_on(outputStream* st) const {
119   _context->print_on(st);
120 }
121 
< prev index next >