/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

/*
 * This file is available under and governed by the GNU General Public
 * License version 2 only, as published by the Free Software Foundation.
 * However, the following notice accompanied the original version of this
 * file:
 *
 * Written by Martin Buchholz with assistance from members of JCP
 * JSR-166 Expert Group and released to the public domain, as
 * explained at http://creativecommons.org/publicdomain/zero/1.0/
 */

/*
 * @test
 * @bug 8054446 8137184 8137185
 * @summary Regression test for memory leak in remove(Object)
 * @run main/othervm -Xmx2200k RemoveLeak
 */

import java.util.concurrent.ConcurrentLinkedQueue;

public class RemoveLeak {
    public static void main(String[] args) {
        int i = 0;
        // Without bug fix, OutOfMemoryError was observed at iteration 65120
        int iterations = 10 * 65120;
        try {
            ConcurrentLinkedQueue<Long> queue = new ConcurrentLinkedQueue<>();
            queue.add(0L);
            while (i++ < iterations) {
                queue.add(1L);
                queue.remove(1L);
            }
        } catch (Error t) {
            System.err.printf("failed at iteration %d/%d%n", i, iterations);
            throw t;
        }
    }
}
