src/share/vm/utilities/chunkedList.cpp

changeset 7333
b12a2a9b05ca
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/utilities/chunkedList.cpp	Thu Oct 02 10:55:36 2014 +0200
     1.3 @@ -0,0 +1,109 @@
     1.4 +/*
     1.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#include "precompiled.hpp"
    1.29 +#include "utilities/chunkedList.hpp"
    1.30 +#include "utilities/debug.hpp"
    1.31 +
    1.32 +/////////////// Unit tests ///////////////
    1.33 +
    1.34 +#ifndef PRODUCT
    1.35 +
    1.36 +template <typename T>
    1.37 +class TestChunkedList {
    1.38 +  typedef ChunkedList<T, mtOther> ChunkedListT;
    1.39 +
    1.40 + public:
    1.41 +  static void testEmpty() {
    1.42 +    ChunkedListT buffer;
    1.43 +    assert(buffer.size() == 0, "assert");
    1.44 +  }
    1.45 +
    1.46 +  static void testFull() {
    1.47 +    ChunkedListT buffer;
    1.48 +    for (uintptr_t i = 0; i < ChunkedListT::BufferSize; i++) {
    1.49 +      buffer.push((T)i);
    1.50 +    }
    1.51 +    assert(buffer.size() == ChunkedListT::BufferSize, "assert");
    1.52 +    assert(buffer.is_full(), "assert");
    1.53 +  }
    1.54 +
    1.55 +  static void testSize() {
    1.56 +    ChunkedListT buffer;
    1.57 +    for (uintptr_t i = 0; i < ChunkedListT::BufferSize; i++) {
    1.58 +      assert(buffer.size() == i, "assert");
    1.59 +      buffer.push((T)i);
    1.60 +      assert(buffer.size() == i + 1, "assert");
    1.61 +    }
    1.62 +  }
    1.63 +
    1.64 +  static void testClear() {
    1.65 +    ChunkedListT buffer;
    1.66 +
    1.67 +    buffer.clear();
    1.68 +    assert(buffer.size() == 0, "assert");
    1.69 +
    1.70 +    for (uintptr_t i = 0; i < ChunkedListT::BufferSize / 2; i++) {
    1.71 +      buffer.push((T)i);
    1.72 +    }
    1.73 +    buffer.clear();
    1.74 +    assert(buffer.size() == 0, "assert");
    1.75 +
    1.76 +    for (uintptr_t i = 0; i < ChunkedListT::BufferSize; i++) {
    1.77 +      buffer.push((T)i);
    1.78 +    }
    1.79 +    buffer.clear();
    1.80 +    assert(buffer.size() == 0, "assert");
    1.81 +  }
    1.82 +
    1.83 +  static void testAt() {
    1.84 +    ChunkedListT buffer;
    1.85 +
    1.86 +    for (uintptr_t i = 0; i < ChunkedListT::BufferSize; i++) {
    1.87 +      buffer.push((T)i);
    1.88 +      assert(buffer.at(i) == (T)i, "assert");
    1.89 +    }
    1.90 +
    1.91 +    for (uintptr_t i = 0; i < ChunkedListT::BufferSize; i++) {
    1.92 +      assert(buffer.at(i) == (T)i, "assert");
    1.93 +    }
    1.94 +  }
    1.95 +
    1.96 +  static void test() {
    1.97 +    testEmpty();
    1.98 +    testFull();
    1.99 +    testSize();
   1.100 +    testClear();
   1.101 +    testAt();
   1.102 +  }
   1.103 +};
   1.104 +
   1.105 +class Metadata;
   1.106 +
   1.107 +void TestChunkedList_test() {
   1.108 +  TestChunkedList<Metadata*>::test();
   1.109 +  TestChunkedList<size_t>::test();
   1.110 +}
   1.111 +
   1.112 +#endif

mercurial