hotspot/test/runtime/ClassUnload/KeepAliveObject.java
author dsamersoff
Sun, 01 May 2016 12:47:00 +0300
changeset 38152 80e5da81fb2c
parent 33730 30e064828045
child 40631 ed82623d7831
permissions -rw-r--r--
8154258: [TESTBUG] Various serviceability tests fail compilation Summary: Replace sun.misc.Unsafe with jdk.internal.misc.Unsafe Reviewed-by: chegar, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17311
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
     1
/*
25958
8dc85547d6d6 8011397: JTREG needs to copy additional WhiteBox class file to JTwork/scratch/sun/hotspot
mgerdin
parents: 17311
diff changeset
     2
 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
17311
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
     4
 *
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
     7
 * published by the Free Software Foundation.
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
     8
 *
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    13
 * accompanied this code).
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    14
 *
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    18
 *
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    21
 * questions.
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    22
 */
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    23
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    24
/*
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    25
 * @test KeepAliveObject
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    26
 * @summary This test case uses a class instance to keep the class alive.
38152
80e5da81fb2c 8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents: 33730
diff changeset
    27
 * @modules java.base/jdk.internal.misc
33730
30e064828045 8140189: [TESTBUG] Get rid of "@library /../../test/lib" in jtreg tests
cjplummer
parents: 28190
diff changeset
    28
 * @library /testlibrary /test/lib /runtime/testlibrary
17311
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    29
 * @library classes
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    30
 * @build KeepAliveObject test.Empty
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    31
 * @build ClassUnloadCommon
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    32
 * @run main ClassFileInstaller sun.hotspot.WhiteBox
25958
8dc85547d6d6 8011397: JTREG needs to copy additional WhiteBox class file to JTwork/scratch/sun/hotspot
mgerdin
parents: 17311
diff changeset
    33
 *                              sun.hotspot.WhiteBox$WhiteBoxPermission
17311
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    34
 * @run main/othervm -Xbootclasspath/a:. -Xmn8m -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI KeepAliveObject
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    35
 */
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    36
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    37
import sun.hotspot.WhiteBox;
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    38
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    39
/**
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    40
 * Test that verifies that classes are not unloaded when specific types of references are kept to them.
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    41
 */
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    42
public class KeepAliveObject {
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    43
  private static final String className = "test.Empty";
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    44
  private static final WhiteBox wb = WhiteBox.getWhiteBox();
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    45
  public static Object escape = null;
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    46
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    47
  public static void main(String... args) throws Exception {
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    48
    ClassLoader cl = ClassUnloadCommon.newClassLoader();
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    49
    Class<?> c = cl.loadClass(className);
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    50
    Object o = c.newInstance();
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    51
    cl = null; c = null;
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    52
    escape = o;
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    53
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    54
    {
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    55
        boolean isAlive = wb.isClassAlive(className);
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    56
        System.out.println("testObject (1) alive: " + isAlive);
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    57
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    58
        ClassUnloadCommon.failIf(!isAlive, "should be alive");
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    59
    }
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    60
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    61
    ClassUnloadCommon.triggerUnloading();
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    62
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    63
    {
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    64
        boolean isAlive = wb.isClassAlive(className);
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    65
        System.out.println("testObject (2) alive: " + isAlive);
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    66
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    67
        ClassUnloadCommon.failIf(!isAlive, "should be alive");
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    68
    }
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    69
    o = null;
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    70
    escape = null;
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    71
    ClassUnloadCommon.triggerUnloading();
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    72
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    73
    {
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    74
        boolean isAlive = wb.isClassAlive(className);
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    75
        System.out.println("testObject (3) alive: " + isAlive);
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    76
        ClassUnloadCommon.failIf(isAlive, "should be unloaded");
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    77
    }
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    78
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    79
  }
6ba3841cb7f9 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
    80
}