jdk/test/sun/reflect/AnonymousNewInstance/ManyNewInstanceAnonTest.java
author jfranck
Thu, 14 Nov 2013 12:17:37 +0100
changeset 21672 33014eb0cb79
parent 21609 f23c375e4baf
child 24366 57c0a8b7a936
permissions -rw-r--r--
8028055: (reflect) invoking Method/Constructor in anonymous classes breaks with -Dsun.reflect.noInflation=true Reviewed-by: briangoetz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21609
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
     1
/*
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
     4
 *
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
     8
 *
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    13
 * accompanied this code).
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    14
 *
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    18
 *
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    21
 * questions.
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    22
 */
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    23
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    24
/*
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    25
 * @test
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    26
 * @bug 7194897
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    27
 * @summary JSR 292: Cannot create more than 16 instances of an anonymous class
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    28
 * @author  Robert Field
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    29
 * @library /lib/testlibrary
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    30
 * @compile -XDignore.symbol.file ManyNewInstanceAnonTest.java
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    31
 * @run main ClassFileInstaller ManyNewInstanceAnonTest
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    32
 * @run main/othervm -Xbootclasspath/a:. -Xverify:all ManyNewInstanceAnonTest
21672
33014eb0cb79 8028055: (reflect) invoking Method/Constructor in anonymous classes breaks with -Dsun.reflect.noInflation=true
jfranck
parents: 21609
diff changeset
    33
 * @run main/othervm -Xbootclasspath/a:. -Xverify:all -Dsun.reflection.noInflation=true ManyNewInstanceAnonTest
21609
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    34
 */
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    35
import java.io.ByteArrayOutputStream;
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    36
import java.io.InputStream;
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    37
import sun.misc.Unsafe;
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    38
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    39
public class ManyNewInstanceAnonTest {
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    40
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    41
    static final int REPS = 20;
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    42
    static final Class<?> klass = ManyNewInstanceAnonTest.class;
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    43
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    44
    public static void main(String[] args) throws Exception {
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    45
        Class<?> c = Unsafe.getUnsafe().defineAnonymousClass(klass, readClassFile(), null);
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    46
        for (int i = 0; i < REPS; ++i) {
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    47
            System.out.printf("%d: %s\n", i, c.newInstance());
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    48
        }
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    49
        System.out.println("Passed.");
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    50
    }
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    51
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    52
    private static byte[] readClassFile() throws Exception {
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    53
        try (InputStream in = klass.getResourceAsStream(klass.getSimpleName() + ".class");
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    54
             ByteArrayOutputStream out = new ByteArrayOutputStream())
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    55
        {
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    56
            int b;
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    57
            while ((b = in.read()) != -1) {
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    58
                out.write(b);
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    59
            }
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    60
            return out.toByteArray();
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    61
        }
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    62
    }
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    63
}