--- /dev/null 2016-08-01 11:03:50.136645000 +0530 +++ new/test/java/awt/Component/ResourceExhaustionTest/ResourceExhaustionTest.java 2016-08-02 15:42:48.548427684 +0530 @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. + * 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. + */ + + +/* + @test + @key headful + @bug 4148117 8160936 + @summary Resource exhaustion by heavyweight components. + @requires (os.family == "windows") + @run main ResourceExhaustionTest +*/ + +import java.awt.Frame; +import java.awt.GridLayout; +import java.awt.Label; +import java.util.Vector; + +public class ResourceExhaustionTest { + + int numLabel = 0; + int numFrame = 0; + Vector frames = new Vector(); + + public static void main(String argv[]) { + ResourceExhaustionTest test = new ResourceExhaustionTest(); + test.runTest(); + } + + // The test creates large number (~2000) of heavyweight components + // to verify that it is possible without running out of resources. + public void runTest() { + try { + for (int i = 0; i < 40; i++) { + numFrame = i; + Frame f = new Frame(String.valueOf(i)); + f.setBounds(10 + i * 4, 10 + i * 10, 400, 300); + f.setLayout(new GridLayout(10, 5)); + + for (int j = 0; j < 50; j++) { + Label l = new Label(i + "," + j); + f.add(l); + numLabel++; + } + f.setVisible(true); + frames.add(f); + } + } catch(Exception e) { + System.out.println("Resources exhausted after creating " + + numFrame + " Frames & " + numLabel + " Labels."); + throw e; + } finally { + dispose(); + } + } + + public void dispose() { + for(int i = 0; i < frames.size(); i++) { + ((Frame)frames.elementAt(i)).dispose(); + } + } +}