src/share/vm/utilities/growableArray.hpp

Print this page


   1 /*
   2  * Copyright (c) 1997, 2008, 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 // A growable array.
  26 
  27 /*************************************************************************/
  28 /*                                                                       */
  29 /*     WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING   */
  30 /*                                                                       */
  31 /* Should you use GrowableArrays to contain handles you must be certain  */
  32 /* the the GrowableArray does not outlive the HandleMark that contains   */
  33 /* the handles. Since GrowableArrays are typically resource allocated    */
  34 /* the following is an example of INCORRECT CODE,                        */
  35 /*                                                                       */
  36 /* ResourceMark rm;                                                      */
  37 /* GrowableArray<Handle>* arr = new GrowableArray<Handle>(size);         */
  38 /* if (blah) {                                                           */
  39 /*    while (...) {                                                      */
  40 /*      HandleMark hm;                                                   */
  41 /*      ...                                                              */
  42 /*      Handle h(THREAD, some_oop);                                      */
  43 /*      arr->append(h);                                                  */
  44 /*    }                                                                  */


 343 // This function clears and deallocate the data in the growable array that
 344 // has been allocated on the C heap.  It's not public - called by the
 345 // destructor.
 346 template<class E> void GrowableArray<E>::clear_and_deallocate() {
 347     assert(on_C_heap(),
 348            "clear_and_deallocate should only be called when on C heap");
 349     clear();
 350     if (_data != NULL) {
 351       for (int i = 0; i < _max; i++) _data[i].~E();
 352       FreeHeap(_data);
 353       _data = NULL;
 354     }
 355 }
 356 
 357 template<class E> void GrowableArray<E>::print() {
 358     tty->print("Growable Array " INTPTR_FORMAT, this);
 359     tty->print(": length %ld (_max %ld) { ", _len, _max);
 360     for (int i = 0; i < _len; i++) tty->print(INTPTR_FORMAT " ", *(intptr_t*)&(_data[i]));
 361     tty->print("}\n");
 362 }


   1 /*
   2  * Copyright (c) 1997, 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_GROWABLEARRAY_HPP
  26 #define SHARE_VM_UTILITIES_GROWABLEARRAY_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "memory/allocation.inline.hpp"
  30 #include "utilities/debug.hpp"
  31 #include "utilities/globalDefinitions.hpp"
  32 #include "utilities/top.hpp"
  33 
  34 // A growable array.
  35 
  36 /*************************************************************************/
  37 /*                                                                       */
  38 /*     WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING   */
  39 /*                                                                       */
  40 /* Should you use GrowableArrays to contain handles you must be certain  */
  41 /* the the GrowableArray does not outlive the HandleMark that contains   */
  42 /* the handles. Since GrowableArrays are typically resource allocated    */
  43 /* the following is an example of INCORRECT CODE,                        */
  44 /*                                                                       */
  45 /* ResourceMark rm;                                                      */
  46 /* GrowableArray<Handle>* arr = new GrowableArray<Handle>(size);         */
  47 /* if (blah) {                                                           */
  48 /*    while (...) {                                                      */
  49 /*      HandleMark hm;                                                   */
  50 /*      ...                                                              */
  51 /*      Handle h(THREAD, some_oop);                                      */
  52 /*      arr->append(h);                                                  */
  53 /*    }                                                                  */


 352 // This function clears and deallocate the data in the growable array that
 353 // has been allocated on the C heap.  It's not public - called by the
 354 // destructor.
 355 template<class E> void GrowableArray<E>::clear_and_deallocate() {
 356     assert(on_C_heap(),
 357            "clear_and_deallocate should only be called when on C heap");
 358     clear();
 359     if (_data != NULL) {
 360       for (int i = 0; i < _max; i++) _data[i].~E();
 361       FreeHeap(_data);
 362       _data = NULL;
 363     }
 364 }
 365 
 366 template<class E> void GrowableArray<E>::print() {
 367     tty->print("Growable Array " INTPTR_FORMAT, this);
 368     tty->print(": length %ld (_max %ld) { ", _len, _max);
 369     for (int i = 0; i < _len; i++) tty->print(INTPTR_FORMAT " ", *(intptr_t*)&(_data[i]));
 370     tty->print("}\n");
 371 }
 372 
 373 #endif // SHARE_VM_UTILITIES_GROWABLEARRAY_HPP