< prev index next >

src/share/vm/utilities/stack.inline.hpp

Print this page


   1 /*
   2  * Copyright (c) 2009, 2016, 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  *
  23  */
  24 
  25 #ifndef SHARE_VM_UTILITIES_STACK_INLINE_HPP
  26 #define SHARE_VM_UTILITIES_STACK_INLINE_HPP
  27 
  28 #include "utilities/align.hpp"
  29 #include "utilities/stack.hpp"

  30 
  31 template <MEMFLAGS F> StackBase<F>::StackBase(size_t segment_size, size_t max_cache_size,
  32                      size_t max_size):
  33   _seg_size(segment_size),
  34   _max_cache_size(max_cache_size),
  35   _max_size(adjust_max_size(max_size, segment_size))
  36 {
  37   assert(_max_size % _seg_size == 0, "not a multiple");
  38 }
  39 
  40 template <MEMFLAGS F> size_t StackBase<F>::adjust_max_size(size_t max_size, size_t seg_size)
  41 {
  42   assert(seg_size > 0, "cannot be 0");
  43   assert(max_size >= seg_size || max_size == 0, "max_size too small");
  44   const size_t limit = max_uintx - (seg_size - 1);
  45   if (max_size == 0 || max_size > limit) {
  46     max_size = limit;
  47   }
  48   return (max_size + seg_size - 1) / seg_size * seg_size;
  49 }


 216 void Stack<E, F>::verify(bool at_empty_transition) const
 217 {
 218   assert(size() <= this->max_size(), "stack exceeded bounds");
 219   assert(this->cache_size() <= this->max_cache_size(), "cache exceeded bounds");
 220   assert(this->_cur_seg_size <= this->segment_size(), "segment index exceeded bounds");
 221 
 222   assert(this->_full_seg_size % this->_seg_size == 0, "not a multiple");
 223   assert(at_empty_transition || is_empty() == (size() == 0), "mismatch");
 224   assert((_cache == NULL) == (this->cache_size() == 0), "mismatch");
 225 
 226   if (is_empty()) {
 227     assert(this->_cur_seg_size == this->segment_size(), "sanity");
 228   }
 229 }
 230 
 231 template <class E, MEMFLAGS F>
 232 void Stack<E, F>::zap_segment(E* seg, bool zap_link_field) const
 233 {
 234   if (!ZapStackSegments) return;
 235   const size_t zap_bytes = segment_bytes() - (zap_link_field ? 0 : sizeof(E*));
 236   uint32_t* cur = (uint32_t*)seg;
 237   const uint32_t* end = cur + zap_bytes / sizeof(uint32_t);
 238   while (cur < end) {
 239     *cur++ = 0xfadfaded;
 240   }
 241 }
 242 #endif
 243 
 244 template <class E, MEMFLAGS F>
 245 E* ResourceStack<E, F>::alloc(size_t bytes)
 246 {
 247   return (E*) resource_allocate_bytes(bytes);
 248 }
 249 
 250 template <class E, MEMFLAGS F>
 251 void ResourceStack<E, F>::free(E* addr, size_t bytes)
 252 {
 253   resource_free_bytes((char*) addr, bytes);
 254 }
 255 
 256 template <class E, MEMFLAGS F>
 257 void StackIterator<E, F>::sync()
 258 {
 259   _full_seg_size = _stack._full_seg_size;
 260   _cur_seg_size = _stack._cur_seg_size;
   1 /*
   2  * Copyright (c) 2009, 2017, 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  *
  23  */
  24 
  25 #ifndef SHARE_VM_UTILITIES_STACK_INLINE_HPP
  26 #define SHARE_VM_UTILITIES_STACK_INLINE_HPP
  27 
  28 #include "utilities/align.hpp"
  29 #include "utilities/stack.hpp"
  30 #include "utilities/copy.hpp"
  31 
  32 template <MEMFLAGS F> StackBase<F>::StackBase(size_t segment_size, size_t max_cache_size,
  33                      size_t max_size):
  34   _seg_size(segment_size),
  35   _max_cache_size(max_cache_size),
  36   _max_size(adjust_max_size(max_size, segment_size))
  37 {
  38   assert(_max_size % _seg_size == 0, "not a multiple");
  39 }
  40 
  41 template <MEMFLAGS F> size_t StackBase<F>::adjust_max_size(size_t max_size, size_t seg_size)
  42 {
  43   assert(seg_size > 0, "cannot be 0");
  44   assert(max_size >= seg_size || max_size == 0, "max_size too small");
  45   const size_t limit = max_uintx - (seg_size - 1);
  46   if (max_size == 0 || max_size > limit) {
  47     max_size = limit;
  48   }
  49   return (max_size + seg_size - 1) / seg_size * seg_size;
  50 }


 217 void Stack<E, F>::verify(bool at_empty_transition) const
 218 {
 219   assert(size() <= this->max_size(), "stack exceeded bounds");
 220   assert(this->cache_size() <= this->max_cache_size(), "cache exceeded bounds");
 221   assert(this->_cur_seg_size <= this->segment_size(), "segment index exceeded bounds");
 222 
 223   assert(this->_full_seg_size % this->_seg_size == 0, "not a multiple");
 224   assert(at_empty_transition || is_empty() == (size() == 0), "mismatch");
 225   assert((_cache == NULL) == (this->cache_size() == 0), "mismatch");
 226 
 227   if (is_empty()) {
 228     assert(this->_cur_seg_size == this->segment_size(), "sanity");
 229   }
 230 }
 231 
 232 template <class E, MEMFLAGS F>
 233 void Stack<E, F>::zap_segment(E* seg, bool zap_link_field) const
 234 {
 235   if (!ZapStackSegments) return;
 236   const size_t zap_bytes = segment_bytes() - (zap_link_field ? 0 : sizeof(E*));
 237   Copy::fill_to_bytes(seg, zap_bytes, badStackSegVal);




 238 }
 239 #endif
 240 
 241 template <class E, MEMFLAGS F>
 242 E* ResourceStack<E, F>::alloc(size_t bytes)
 243 {
 244   return (E*) resource_allocate_bytes(bytes);
 245 }
 246 
 247 template <class E, MEMFLAGS F>
 248 void ResourceStack<E, F>::free(E* addr, size_t bytes)
 249 {
 250   resource_free_bytes((char*) addr, bytes);
 251 }
 252 
 253 template <class E, MEMFLAGS F>
 254 void StackIterator<E, F>::sync()
 255 {
 256   _full_seg_size = _stack._full_seg_size;
 257   _cur_seg_size = _stack._cur_seg_size;
< prev index next >