jdk/test/java/util/concurrent/ConcurrentLinkedQueue/RemoveLeak.java
author vlivanov
Wed, 02 Mar 2016 15:42:03 +0300
changeset 36349 6cc8e6f596b2
parent 32991 b27c76b82713
child 40279 7a1e94e544d6
permissions -rw-r--r--
8151020: [TESTBUG] UnsafeGetStableArrayElement::testL_* fail intermittently Reviewed-by: zmajo, shade
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32991
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
     1
/*
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
     3
 *
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
     6
 * published by the Free Software Foundation.
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
     7
 *
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
     8
 * This code is distributed in the hope that it will be useful, but WITHOUT
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
     9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    10
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    11
 * version 2 for more details (a copy is included in the LICENSE file that
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    12
 * accompanied this code).
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    13
 *
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License version
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    15
 * 2 along with this work; if not, write to the Free Software Foundation,
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    16
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    17
 *
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    18
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    19
 * or visit www.oracle.com if you need additional information or have any
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    20
 * questions.
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    21
 */
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    22
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    23
/*
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    24
 * This file is available under and governed by the GNU General Public
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    25
 * License version 2 only, as published by the Free Software Foundation.
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    26
 * However, the following notice accompanied the original version of this
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    27
 * file:
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    28
 *
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    29
 * Written by Martin Buchholz with assistance from members of JCP
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    30
 * JSR-166 Expert Group and released to the public domain, as
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    31
 * explained at http://creativecommons.org/publicdomain/zero/1.0/
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    32
 */
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    33
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    34
/*
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    35
 * @test
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    36
 * @bug 8054446 8137184 8137185
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    37
 * @summary Regression test for memory leak in remove(Object)
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    38
 * @run main/othervm -Xmx2200k RemoveLeak
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    39
 */
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    40
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    41
import java.util.concurrent.ConcurrentLinkedQueue;
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    42
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    43
public class RemoveLeak {
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    44
    public static void main(String[] args) {
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    45
        int i = 0;
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    46
        // Without bug fix, OutOfMemoryError was observed at iteration 65120
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    47
        int iterations = 10 * 65120;
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    48
        try {
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    49
            ConcurrentLinkedQueue<Long> queue = new ConcurrentLinkedQueue<>();
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    50
            queue.add(0L);
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    51
            while (i++ < iterations) {
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    52
                queue.add(1L);
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    53
                queue.remove(1L);
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    54
            }
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    55
        } catch (Error t) {
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    56
            System.err.printf("failed at iteration %d/%d%n", i, iterations);
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    57
            throw t;
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    58
        }
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    59
    }
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents:
diff changeset
    60
}