test/jdk/java/awt/AppContext/ApplicationThreadsStop/ApplicationThreadsStop.java
author fyang
Mon, 04 Nov 2019 16:10:39 +0800
changeset 59307 fc216dcef2bb
parent 47216 71c04702a3d5
permissions -rw-r--r--
8233466: aarch64: remove unnecessary load of mdo when profiling return and parameters type Reviewed-by: adinn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33255
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
     1
/*
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
     4
 *
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
     8
 *
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    13
 * accompanied this code).
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    14
 *
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    18
 *
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    21
 * questions.
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    22
 */
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    23
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    24
import java.awt.AWTException;
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    25
import java.awt.Frame;
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    26
import java.awt.Robot;
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    27
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    28
import sun.awt.AppContext;
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    29
import sun.awt.SunToolkit;
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    30
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    31
/**
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    32
 * @test
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 33255
diff changeset
    33
 * @key headful
33255
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    34
 * @bug 8136858
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    35
 * @modules java.desktop/sun.awt
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    36
 * @run main/othervm/java.security.policy=java.policy -Djava.security.manager ApplicationThreadsStop
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    37
 */
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    38
public final class ApplicationThreadsStop implements Runnable {
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    39
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    40
    private static AppContext contextToDispose;
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    41
    private static Thread thread;
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    42
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    43
    public static void main(final String[] args) throws Exception {
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    44
        ThreadGroup tg = new ThreadGroup("TestThreadGroup");
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    45
        Thread t = new Thread(tg, new ApplicationThreadsStop());
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    46
        t.start();
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    47
        t.join();
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    48
        contextToDispose.dispose();
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    49
        // wait for appcontext to be destroyed
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    50
        Thread.sleep(10000);
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    51
        if(thread.isAlive()){
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    52
            throw new RuntimeException("Thread is alive");
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    53
        }
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    54
    }
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    55
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    56
    @Override
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    57
    public void run() {
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    58
        contextToDispose = SunToolkit.createNewAppContext();
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    59
        Frame f = new Frame();
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    60
        f.setSize(300, 300);
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    61
        f.setLocationRelativeTo(null);
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    62
        f.setVisible(true);
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    63
        thread = new Thread(() -> {
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    64
            while(true);
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    65
        });
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    66
        thread.start();
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    67
        sync();
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    68
    }
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    69
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    70
    private static void sync() {
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    71
        try {
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    72
            new Robot().waitForIdle();
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    73
        } catch (AWTException e) {
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    74
            throw new RuntimeException(e);
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    75
        }
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    76
    }
110d90e1552f 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext
serb
parents:
diff changeset
    77
}