changeset 59:f79609513cfc

indy-bsm: passes old and new unit tests
author jrose
date Fri, 09 Jul 2010 15:44:03 -0700
parents 15afb13fc4a6
children 5fd2ac635231
files indy-bsm-6964498.patch
diffstat 1 files changed, 94 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/indy-bsm-6964498.patch	Sun Jul 04 00:51:01 2010 -0700
+++ b/indy-bsm-6964498.patch	Fri Jul 09 15:44:03 2010 -0700
@@ -507,7 +507,7 @@
 +            bootm = make.at(bsmPos).NewClass(null, null,
 +                                             make.Type(classValue),
 +                                             sampleArgs, null);
-+        Env<AttrContext> localEnv = env.enclosing(JCTree.TOPLEVEL);
++        Env<AttrContext> localEnv = env.enclosing(JCTree.CLASSDEF);
 +        localEnv = localEnv.dup(tree, localEnv.info.dup());
 +        Type bsmtype = attribExpr(make.TypeCast(syms.callSiteType, bootm), localEnv);
 +        if (bsmtype.isErroneous())  return null;
@@ -1164,42 +1164,116 @@
 new file mode 100644
 --- /dev/null
 +++ b/test/tools/javac/meth/IndyLocalBootstrap.java
-@@ -0,0 +1,38 @@
+@@ -0,0 +1,112 @@
++/*
++ * Copyright 2010 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
++ * CA 95054 USA or visit www.sun.com if you need additional information or
++ * have any questions.
++ */
++
++/*
++ * @test
++ * @bug 6964498
++ * @summary Test localized bootstrap methods
++ * @author jrose
++ *
++ * @library ..
++ * @compile -source 7 -target 7 IndyLocalBootstrap.java
++ */
++//Not yet: @run main/othervm -XX:+EnableInvokeDynamic meth.IndyLocalBootstrap
++
++/*
++ * Standalone testing:
++ * <code>
++ * $ cd $MY_REPO_DIR/langtools
++ * $ (cd make; make)
++ * $ ./dist/bootstrap/bin/javac -d dist test/tools/javac/meth/IndyLocalBootstrap.java
++ * $ ./dist/bootstrap/bin/javap -c -classpath dist meth.IndyLocalBootstrap
++ * </code>
++ */
++
++package meth;
++
 +import java.dyn.*;
 +
 +@BootstrapMethod(value=IndyLocalBootstrap.class, name="classBSM")
 +class IndyLocalBootstrap {
 +    public static void main(String... args) throws Throwable {
++        new IndyLocalBootstrap().run(args);
++    }
++    void run(String... args) throws Throwable {
 +        System.out.println("starting");
-+        InvokeDynamic.<@BootstrapMethod(FancySite.class) Object>foo1();
-+        System.out.println("halfway through");
-+        InvokeDynamic.foo2(); //use classBSM
++        doFoo1();
++        System.out.println("one test done");
++        Object x = InvokeDynamic.foo2(2); //use classBSM
++        System.out.println("one more test");
++        doFoo3();
 +        System.out.println("all done");
 +    }
 +
-+    static Object classBSM(Object caller, Object name, Object type) {
-+        return new FancySite((Class)caller, (String)name, (MethodType)type);
++    //@BootstrapMethod(FancySite.class, name="make")
++    private static Object doFoo1() throws Throwable {
++        return InvokeDynamic.<@BootstrapMethod(value=FancySite.class, name="make") Object>foo1();
 +    }
 +
-+    static class FancySite extends CallSite {
-+        FancySite(Class<?> caller, String name, MethodType type) {
-+            setTarget(MethodHandles.collectArguments(handler_MH
-+                                                     .bindTo(name)
-+                                                     .bindTo(type),
-+                                                     type));
++    @BootstrapMethod(FancySite.class)
++    private static void doFoo3() throws Throwable {
++        InvokeDynamic.<void>foo3("three"); //use FancySite
++    }
++
++    // /* //BAD
++    static //*/
++    Object classBSM(Object caller, Object name, Object type) {
++        return new FancySite((Class)caller, (String)name, (MethodType)type, "IndyLocalBootstrap.classBSM");
++    }
++
++    private static class FancySite extends CallSite {
++        // Save some random parameters:
++        final String name;
++        final String whence;
++        private FancySite(Class<?> caller, String name, MethodType type) {
++            this(caller, name, type, "FancySite.<init>");
++        }
++        private FancySite(Class<?> caller, String name, MethodType type, String whence) {
++            this.name = name;
++            this.whence = whence;
++            MethodHandle handler = handler_MH.bindTo(this);  // = this#handler(...)
++            setTarget(MethodHandles.collectArguments(handler, type));
 +        }
 +
-+        private static Object handler(String name, MethodType type, Object... args) {
-+            System.out.println("Fancy call "+name+type+" "+java.util.Arrays.asList(args));
++        private Object handler(Object... args) {
++            System.out.println("Fancy call (BSM from "+whence+") "+name+getTarget().type()+" "+java.util.Arrays.asList(args));
 +            return null;
 +        }
-+        private final static MethodHandle handler_MH;
++
++        private static final MethodHandle handler_MH;
 +        static {
 +            MethodHandles.Lookup lookup = MethodHandles.lookup();
-+            handler_MH = lookup.findStatic(lookup.lookupClass(),
-+                "handler", MethodType.methodType(Object.class,
-+                                                 String.class, MethodType.class,
-+                                                 Object[].class));
++            handler_MH = // FancySite#handler(...)
++                lookup.findVirtual(lookup.lookupClass(), "handler",
++                    MethodType.methodType(Object.class, Object[].class));
++        }
++
++        // test inner class access to privates
++        private static CallSite make(Class<?> caller, String name, MethodType type) {
++            return new FancySite(caller, name, type, "FancySite.make");
 +        }
 +    }
 +}