1 /* 2 * Copyright 2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 20 * CA 95054 USA or visit www.sun.com if you need additional information or 21 * have any questions. 22 * 23 */ 24 25 StackBase::StackBase(size_t segment_size, size_t max_cache_size, 26 size_t max_size): 27 _seg_size(segment_size), 28 _max_cache_size(max_cache_size), 29 _max_size(adjust_max_size(max_size, segment_size)) 30 { 31 assert(_max_size % _seg_size == 0, "not a multiple"); 32 } 33 34 size_t StackBase::adjust_max_size(size_t max_size, size_t seg_size) 35 { 36 assert(seg_size > 0, "cannot be 0"); 37 assert(max_size >= seg_size || max_size == 0, "max_size too small"); 38 const size_t limit = max_uintx - (seg_size - 1); 39 if (max_size == 0 || max_size > limit) { 40 max_size = limit; 41 } 42 return (max_size + seg_size - 1) / seg_size * seg_size; 43 } 44 254 void StackIterator<E>::sync() 255 { 256 _full_seg_size = _stack._full_seg_size; 257 _cur_seg_size = _stack._cur_seg_size; 258 _cur_seg = _stack._cur_seg; 259 } 260 261 template <class E> 262 E* StackIterator<E>::next_addr() 263 { 264 assert(!is_empty(), "no items left"); 265 if (_cur_seg_size == 1) { 266 E* addr = _cur_seg; 267 _cur_seg = _stack.get_link(_cur_seg); 268 _cur_seg_size = _stack.segment_size(); 269 _full_seg_size -= _stack.segment_size(); 270 return addr; 271 } 272 return _cur_seg + --_cur_seg_size; 273 } | 1 /* 2 * Copyright (c) 2009, 2010, 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/stack.hpp" 29 30 StackBase::StackBase(size_t segment_size, size_t max_cache_size, 31 size_t max_size): 32 _seg_size(segment_size), 33 _max_cache_size(max_cache_size), 34 _max_size(adjust_max_size(max_size, segment_size)) 35 { 36 assert(_max_size % _seg_size == 0, "not a multiple"); 37 } 38 39 size_t StackBase::adjust_max_size(size_t max_size, size_t seg_size) 40 { 41 assert(seg_size > 0, "cannot be 0"); 42 assert(max_size >= seg_size || max_size == 0, "max_size too small"); 43 const size_t limit = max_uintx - (seg_size - 1); 44 if (max_size == 0 || max_size > limit) { 45 max_size = limit; 46 } 47 return (max_size + seg_size - 1) / seg_size * seg_size; 48 } 49 259 void StackIterator<E>::sync() 260 { 261 _full_seg_size = _stack._full_seg_size; 262 _cur_seg_size = _stack._cur_seg_size; 263 _cur_seg = _stack._cur_seg; 264 } 265 266 template <class E> 267 E* StackIterator<E>::next_addr() 268 { 269 assert(!is_empty(), "no items left"); 270 if (_cur_seg_size == 1) { 271 E* addr = _cur_seg; 272 _cur_seg = _stack.get_link(_cur_seg); 273 _cur_seg_size = _stack.segment_size(); 274 _full_seg_size -= _stack.segment_size(); 275 return addr; 276 } 277 return _cur_seg + --_cur_seg_size; 278 } 279 280 #endif // SHARE_VM_UTILITIES_STACK_INLINE_HPP |