jdk/test/java/lang/invoke/lambda/RepetitiveLambdaSerialization.java
author rfield
Mon, 04 Nov 2013 10:12:18 -0800
changeset 21609 f23c375e4baf
child 21672 33014eb0cb79
permissions -rw-r--r--
7194897: JSR 292: Cannot create more than 16 instances of an anonymous class 8027681: Lambda serialization fails once reflection proxy generation kicks in Reviewed-by: ksrini, briangoetz, jfranck Contributed-by: joel.franck@oracle.com, brian.goetz@oracle.com, robert.field@oracle.com
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 8027681
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    27
 * @summary Lambda serialization fails once reflection proxy generation kicks in
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
 * @run main/othervm RepetitiveLambdaSerialization
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    30
 */
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    31
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    32
import java.io.*;
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    33
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    34
public class RepetitiveLambdaSerialization {
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    35
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    36
    static final int REPS = 20;
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    37
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    38
    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
    39
        LSI ls = z -> "[" + z + "]";
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    40
        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
    41
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    42
            ObjectOutput out = new ObjectOutputStream(baos);
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    43
            out.writeObject(ls);
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    44
            out.flush();
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    45
            out.close();
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    46
        }
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    47
        System.out.println("Passed.");
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
}
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
interface LSI extends Serializable {
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    52
    String convert(String x);
f23c375e4baf 7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
rfield
parents:
diff changeset
    53
}