meth: update project file
authorjrose
Sat Aug 16 01:30:55 2008 -0700 (15 months ago)
changeset 1400ab99cf1d52
parent 1316e7bac86f4c
child 15e205623138c2
meth: update project file
factor sources into the JDK repository, where they belong
meth.proj.patch
--- a/meth.proj.patch Sat Aug 16 00:31:07 2008 -0700
+++ b/meth.proj.patch Sat Aug 16 01:30:55 2008 -0700
@@ -1,7 +1,7 @@ diff --git a/src/share/projects/meth/REA
-diff --git a/src/share/projects/meth/README.txt b/src/share/projects/meth/README.txt
+diff --git a/src/share/projects/MethodHandle/README.txt b/src/share/projects/MethodHandle/README.txt
new file mode 100644
--- /dev/null
-+++ b/src/share/projects/meth/README.txt
++++ b/src/share/projects/MethodHandle/README.txt
@@ -0,0 +1,21 @@
+Standalone NetBeans project of JSR 292 RI
+
@@ -24,11 +24,25 @@ new file mode 100644
+
+Simpler (currently broken) demo:
+ gamma -Xbootclasspath/a:dist/MethodHandle.jar MethodHandleDemo
-diff --git a/src/share/projects/meth/build.xml b/src/share/projects/meth/build.xml
+diff --git a/src/share/projects/MethodHandle/TEST.sh b/src/share/projects/MethodHandle/TEST.sh
+new file mode 100755
+--- /dev/null
++++ b/src/share/projects/MethodHandle/TEST.sh
+@@ -0,0 +1,9 @@
++#! /bin/ksh
++#NetBeansResources=$(find /Applications/NetBeans* -type d -name Resources | tail -1)
++#NetBeansResources="/Applications/NetBeans/NetBeans 6.1.app/Contents/Resources"
++#junit="$NetBeansResources/NetBeans/java2/modules/ext/junit-3.8.2.jar"
++export junit=$HOME/env/jars/junit-3.8.2.jar
++export akproj="$HOME/Projects/AnonymousClass"
++export mhproj="$HOME/Projects/MethodHandle"
++export cpath="$mhproj/build/classes:$mhproj/build/test/classes:$junit:$akproj/build/classes:"
++java -Xbootclasspath/a:"$cpath" jdk.java.dyn.MethodHandleDemo
+diff --git a/src/share/projects/MethodHandle/build.xml b/src/share/projects/MethodHandle/build.xml
new file mode 100644
--- /dev/null
-+++ b/src/share/projects/meth/build.xml
-@@ -0,0 +1,146 @@
++++ b/src/share/projects/MethodHandle/build.xml
+@@ -0,0 +1,125 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- You may freely edit this file. See commented blocks below for -->
+<!-- some examples of how to customize the build. -->
@@ -42,27 +56,6 @@ new file mode 100644
+ run.jvmargs=-Xbootclasspath/a:${build.classes.dir}:${local.junit.jar}
+ -->
+ <property name="--broken--run.jvmargs" value="-Xbootclasspath/a:${build.classes.dir}:${local.junit.jar}"/>
-+
-+ <target name="-pre-compile-test">
-+ <!--
-+ <copy file="${libs.junit.classpath}" tofile="${local.junit.jar}"/>
-+ -->
-+ <mkdir dir="${build.dir}/handl3"/>
-+ <echo level="info" message="junit classpath: ${libs.junit.classpath}"/>
-+ <echo level="info" message="-pre-compile-test MethodHandl3 in ${test.src.dir} => ${build.dir}/handl3"/>
-+ <javac srcdir="${test.src.dir}"
-+ destdir="${build.dir}/handl3"
-+ includes="**/*Handl3.java"
-+ classpath="${build.classes.dir}"
-+ />
-+ <java
-+ classname="java.dyn.InstallMethodHandl3"
-+ >
-+ <jvmarg value="-Xbootclasspath/a:${build.dir}/handl3"/>
-+ <arg file="${build.dir}/handl3"/>
-+ </java>
-+ <echo level="info" message="done with -pre-compile-test"/>
-+ </target>
+
+ <property name="javadoc.includes" value="java/dyn/*.java"/>
+
@@ -175,20 +168,15 @@ new file mode 100644
+
+ -->
+</project>
-diff --git a/src/share/projects/meth/build/handl3/README.txt b/src/share/projects/meth/build/handl3/README.txt
+diff --git a/src/share/projects/MethodHandle/nbproject/project.properties b/src/share/projects/MethodHandle/nbproject/project.properties
new file mode 100644
--- /dev/null
-+++ b/src/share/projects/meth/build/handl3/README.txt
-@@ -0,0 +1,1 @@
-+this directory hold a non-standard MethodHandle, used in compilation environments
-diff --git a/src/share/projects/meth/nbproject/project.properties b/src/share/projects/meth/nbproject/project.properties
-new file mode 100644
---- /dev/null
-+++ b/src/share/projects/meth/nbproject/project.properties
-@@ -0,0 +1,70 @@
++++ b/src/share/projects/MethodHandle/nbproject/project.properties
+@@ -0,0 +1,75 @@
+application.args=
+application.title=MethodHandle
+application.vendor=jrose
++auxiliary.org-netbeans-modules-editor-indent.CodeStyle.usedProfile=default
+build.classes.dir=${build.dir}/classes
+build.classes.excludes=**/*.java,**/*.form
+# This directory is removed when the project is cleaned:
@@ -207,40 +195,41 @@ new file mode 100644
+dist.jar=${dist.dir}/MethodHandle.jar
+dist.javadoc.dir=${dist.dir}/javadoc
+excludes=
-+file.reference.build-handl3=${build.dir}/handl3
-+includes=**
++includes=java/dyn/**,jdk/java/dyn/**,sun/misc/Unsafe.java
++#includes=**
+jar.compress=false
-+javac.classpath=
++javac.classpath=\
++ ${reference.AnonymousClass.jar}
+# Space-separated list of extra javac options
+javac.compilerargs=-Xlint:unchecked
+javac.deprecation=false
+javac.source=1.5
+javac.target=1.5
+javac.test.classpath=\
-+ ${file.reference.build-handl3}:\
+ ${javac.classpath}:\
+ ${build.classes.dir}:\
-+ ${libs.junit.classpath}
++ ${libs.junit_4.classpath}
+javadoc.additionalparam=
+javadoc.author=false
+javadoc.encoding=
-+javadoc.noindex=false
-+javadoc.nonavbar=false
-+javadoc.notree=false
++javadoc.noindex=true
++javadoc.nonavbar=true
++javadoc.notree=true
+javadoc.private=false
-+javadoc.splitindex=true
++javadoc.splitindex=false
+javadoc.use=true
+javadoc.version=false
+javadoc.windowtitle=
+jnlp.codebase.type=local
-+jnlp.codebase.url=file:/Users/jrose/Projects/MethodHandle/dist/
++jnlp.descriptor=application
+jnlp.enabled=false
+jnlp.offline-allowed=false
+jnlp.signed=false
-+main.class=MethodHandleDemo
+manifest.file=manifest.mf
+meta.inf.dir=${src.dir}/META-INF
+platform.active=JDK_1.6
++project.AnonymousClass=../AnonymousClass
++reference.AnonymousClass.jar=${project.AnonymousClass}/dist/AnonymousClass.jar
+run.classpath=\
+ ${javac.classpath}:\
+ ${build.classes.dir}
@@ -251,16 +240,19 @@ new file mode 100644
+ ${javac.test.classpath}:\
+ ${build.test.classes.dir}
+source.encoding=UTF-8
-+src.dir=src
++# One or both refs probably need fixing:
++file.reference.projects=${env.HOME}/Projects
++file.reference.davinci.sources.jdk=${file.reference.projects}/davinci/sources/jdk
++src.classes.dir=${file.reference.davinci.sources.jdk}/src/share/classes
+test.src.dir=test
+project.license=openjdk
+##platform.bootclasspath=${build.classes.dir}:${libs.junit.classpath}
-+run.jvmargs=-Xbootclasspath/a:"${build.classes.dir}:${libs.junit.classpath}"
-diff --git a/src/share/projects/meth/nbproject/project.xml b/src/share/projects/meth/nbproject/project.xml
++run.jvmargs=-Xbootclasspath/a:"${build.classes.dir}:${reference.AnonymousClass.jar}:${libs.junit.classpath}"
+diff --git a/src/share/projects/MethodHandle/nbproject/project.xml b/src/share/projects/MethodHandle/nbproject/project.xml
new file mode 100644
--- /dev/null
-+++ b/src/share/projects/meth/nbproject/project.xml
-@@ -0,0 +1,17 @@
++++ b/src/share/projects/MethodHandle/nbproject/project.xml
+@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://www.netbeans.org/ns/project/1">
+ <type>org.netbeans.modules.java.j2seproject</type>
@@ -270,2905 +262,61 @@ new file mode 100644
+ <minimum-ant-version>1.6.5</minimum-ant-version>
+ <explicit-platform explicit-source-supported="true"/>
+ <source-roots>
-+ <root id="src.dir"/>
++ <root id="src.classes.dir" name="Source Packages"/>
+ </source-roots>
+ <test-roots>
+ <root id="test.src.dir"/>
+ </test-roots>
+ </data>
++ <references xmlns="http://www.netbeans.org/ns/ant-project-references/1">
++ <reference>
++ <foreign-project>AnonymousClass</foreign-project>
++ <artifact-type>jar</artifact-type>
++ <script>build.xml</script>
++ <target>jar</target>
++ <clean-target>clean</clean-target>
++ <id>jar</id>
++ </reference>
++ </references>
+ </configuration>
+</project>
-diff --git a/src/share/projects/meth/src/MethodHandleDemo.java b/src/share/projects/meth/src/MethodHandleDemo.java
+diff --git a/src/share/projects/MethodHandle/test/jdk/java/dyn/MethodHandleBytecodeTest.java b/src/share/projects/MethodHandle/test/jdk/java/dyn/MethodHandleBytecodeTest.java
new file mode 100644
--- /dev/null
-+++ b/src/share/projects/meth/src/MethodHandleDemo.java
-@@ -0,0 +1,64 @@
-+//
-+// MethodHandleDemo.java
-+// MethodHandle
-+//
-+// Created by John Rose on 6/12/07.
-+// Copyright 2007 __MyCompanyName__. All rights reserved.
-+//
-+
-+//package '';
-+import java.dyn.*;
-+import java.lang.reflect.*;
-+import java.util.*;
-+
-+public class MethodHandleDemo {
-+
-+ public static void main(String... av) {
-+ Class caller = MethodHandleDemo.class;
-+ Class returnType = String.class;
-+ Class[] signature = {String.class};
-+ String result;
-+// MethodCall mc
-+// = new MethodCall(caller, "test", returnType, signature);
-+// result = idi.<String,RuntimeException>invoke("hello", "world");
-+ MethodHandle mh0 = MethodHandles.findVirtual(Object.class,
-+ "toString", MethodType.make(String.class));
-+ System.out.println("found "+mh0);
-+ MethodHandle mh = MethodHandles.findStatic(MethodHandleDemo.class,
-+ "test0", MethodType.make(String.class));
-+ System.out.println("calling "+mh);
-+ result = null; //(String) MethodHandles.invoke(mh.type(), mh);
-+ System.out.println(result);
-+ }
-+
-+ // static methods we make handles for:
-+ public static String test0() {
-+ return "[test0]";
-+ }
-+
-+ public static String test1(String x) {
-+ return "[test1 " + x + "]";
-+ }
-+
-+ public static String test2(String x, String y) {
-+ return "[test2 " + x + " " + y + "]";
-+ }
-+
-+ // virtual methods we make handles for:
-+ static class Obj {
-+
-+ String x;
-+
-+ Obj(String x) {
-+ this.x = x;
-+ }
-+
-+ public String test1() {
-+ return "[test1 " + x + "]";
-+ }
-+
-+ public String test2(String y) {
-+ return "[test2 " + x + " " + y + "]";
-+ }
-+ }
-+}
-diff --git a/src/share/projects/meth/src/java/dyn/CallSite.java b/src/share/projects/meth/src/java/dyn/CallSite.java
-new file mode 100644
---- /dev/null
-+++ b/src/share/projects/meth/src/java/dyn/CallSite.java
-@@ -0,0 +1,75 @@
++++ b/src/share/projects/MethodHandle/test/jdk/java/dyn/MethodHandleBytecodeTest.java
+@@ -0,0 +1,87 @@
+/*
+ * Copyright 2008 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
++ * under the terms make the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
-+ *
++ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
-+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
++ * ANY WARRANTY; without even the implied warranty make 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
++ *
++ * You should have received a copy make 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.
+ */
+
-+package java.dyn;
-+
-+/**
-+ * An <code>invokedynamic</code> call site, as reified to the bootstrap method.
-+ * Every instance of a call site corresponds to a distinct instance
-+ * of the <code>invokedynamic</code> instruction.
-+ * Call sites have state, one reference word, called the <code>target</code>,
-+ * and typed as a {@link MethodHandle}. When this state is null (as it is
-+ * initially) the call site is in the unlinked state. Otherwise, it is said
-+ * to be linked to its target.
-+ * <p>
-+ * When an unlinked call site is executed, a bootstrap routine is called
-+ * to finish the execution of the call site, and optionally to link
-+ * the call site.
-+ * <p>
-+ * FIXME: Make this into a concrete (but non-final) class.
-+ * @author jrose
-+ */
-+public interface CallSite {
-+ /**
-+ * Report the current linkage state of the call site. (This is mutable.)
-+ * @return the current linkage state of the call site
-+ */
-+ public MethodHandle getTarget();
-+
-+ /**
-+ * Link or relink the call site, by setting its target method.
-+ * @param target the new target, or null if it is to be unlinked
-+ */
-+ public void setTarget(MethodHandle target);
-+
-+ /**
-+ * Report the class containing the call site. (This is immutable static context.)
-+ * @return class containing the call site
-+ */
-+ Class callerClass();
-+
-+ /**
-+ * Report the method name specified in the {@code invokedynamic} instruction. (This is immutable static context.)
-+ * @return method name specified by the call site
-+ */
-+ String name();
-+
-+ /*
-+ * Report the result and parameter types, derived from the invocation descriptor, and resolved
-+ * against the calling class's class loader. (This is immutable static context.)
-+ * @return method type specified by the call site
-+ */
-+ MethodType type();
-+}
-diff --git a/src/share/projects/meth/src/java/dyn/Dynamic.java b/src/share/projects/meth/src/java/dyn/Dynamic.java
-new file mode 100644
---- /dev/null
-+++ b/src/share/projects/meth/src/java/dyn/Dynamic.java
-@@ -0,0 +1,37 @@
-+/*
-+ * Copyright 2008 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. Sun designates this
-+ * particular file as subject to the "Classpath" exception as provided
-+ * by Sun in the LICENSE file that accompanied this code.
-+ *
-+ * 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.
-+ */
-+
-+package java.dyn;
-+
-+/**
-+ * Syntactic marker interface for {@code invokedynamic} instructions.
-+ * This type has no particular meaning as a class or interface supertype, and need never be implemented by any class.
-+ * Logically, it denotes a dynamically typed reference to any object.
-+ * As such it may be viewed as logically containing all methods on any of those types.
-+ * @author jrose
-+ */
-+public class Dynamic {
-+ // no methods
-+}
-diff --git a/src/share/projects/meth/src/java/dyn/Linkage.java b/src/share/projects/meth/src/java/dyn/Linkage.java
-new file mode 100644
---- /dev/null
-+++ b/src/share/projects/meth/src/java/dyn/Linkage.java
-@@ -0,0 +1,111 @@
-+package java.dyn;
-+
-+/*
-+ * Copyright 2008 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. Sun designates this
-+ * particular file as subject to the "Classpath" exception as provided
-+ * by Sun in the LICENSE file that accompanied this code.
-+ *
-+ * 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.
-+ */
-+
-+/**
-+ *
-+ * @author jrose
-+ */
-+public class Linkage {
-+ /**
-+ * Register a bootstrap method for use for a given caller class.
-+ * The method handle must be of a type equivalent to {@link Linkage#bootstrapInvokeDynamic}.
-+ * <p>
-+ * The operation will fail with an exception if any of the following conditions hold:
-+ * <ul>
-+ * <li>The caller of this method is in a different package than the {@code callerClass},
-+ * and there is a security manager, and its {@code checkPermission} call throws
-+ * when passed {@link LinkagePermission("registerBootstrapMethod",callerClass)}.
-+ * <li>The given class already has a bootstrap method, either from an embedded
-+ * {@code BootstrapInvokeDynamic} classfile attribute, or from a previous
-+ * call to this method.
-+ * <li>The given class is already fully initialized.
-+ * <li>The given class is in the process of initialization, in another thread.
-+ * </ul>
-+ * Because of these rules, a class may install its own bootstrap method in
-+ * a static initializer.
-+ */
-+ void registerBootstrapMethod(Class callerClass, MethodHandle mh) {
-+ SecurityManager security = System.getSecurityManager();
-+ if (security != null) {
-+ // FIXME: do not run this check if my caller and callerClass are package-mates.
-+ security.checkPermission(new LinkagePermission("registerBootstrapMethod",callerClass));
-+ }
-+ throw new UnsupportedOperationException("NYI");
-+ }
-+
-+ /** Determine if the caller class has declared or registered its own bootstrap method.
-+ * If so, delegate this call to it. Otherwise, throw an IncompatibleClassChangeError.
-+ */
-+ public static
-+ Object bootstrapInvokeDynamic(CallSite site, Object... receiverAndArguments) {
-+ throw new UnsupportedOperationException("NYI");
-+ }
-+
-+ /**
-+ * Invalidate all <code>invokedynamic</code> call sites everywhere.
-+ * <p>
-+ * When this method returns, every <code>invokedynamic</code> instruction
-+ * will invoke its bootstrap method on next call.
-+ * <p>
-+ * It is unspecified whether call sites already known to the Java
-+ * code will continue to be associated with <code>invokedynamic</code>
-+ * instructions. If any call site is still so associated, its
-+ * {@link CallSite#getTarget()} method is guaranteed to return null
-+ * the invalidation operation completes.
-+ * <p>
-+ * Invalidation operations are likely to be slow. Use them sparingly.
-+ */
-+ public static
-+ Object invalidateAll() {
-+ SecurityManager security = System.getSecurityManager();
-+ if (security != null) {
-+ security.checkPermission(new LinkagePermission("invalidateAll"));
-+ }
-+ throw new UnsupportedOperationException("NYI");
-+ }
-+
-+ /**
-+ * Invalidate all <code>invokedynamic</code> call sites associated
-+ * with the given class.
-+ * (These are exactly those sites which report the given class
-+ * via the {@link CallSite#callerClass()} method.)
-+ * <p>
-+ * When this method returns, every matching <code>invokedynamic</code>
-+ * instruction will invoke its bootstrap method on next call.
-+ * <p>
-+ * For additional semantics of call site invalidation,
-+ * see {@link #invalidateAll()}.
-+ */
-+ public static
-+ Object invalidateCallerClass(Class<?> callerClass) {
-+ SecurityManager security = System.getSecurityManager();
-+ if (security != null) {
-+ security.checkPermission(new LinkagePermission("invalidateAll", callerClass));
-+ }
-+ throw new UnsupportedOperationException("NYI");
-+ }
-+}
-diff --git a/src/share/projects/meth/src/java/dyn/LinkagePermission.java b/src/share/projects/meth/src/java/dyn/LinkagePermission.java
-new file mode 100644
---- /dev/null
-+++ b/src/share/projects/meth/src/java/dyn/LinkagePermission.java
-@@ -0,0 +1,111 @@
-+/*
-+ * Copyright 2008 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. Sun designates this
-+ * particular file as subject to the "Classpath" exception as provided
-+ * by Sun in the LICENSE file that accompanied this code.
-+ *
-+ * 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.
-+ */
-+
-+package java.dyn;
-+
-+import java.security.*;
-+import java.util.Enumeration;
-+import java.util.Hashtable;
-+import java.util.StringTokenizer;
-+
-+/**
-+ * This class is for runtime permissions. A RuntimePermission
-+ * contains a name (also referred to as a "target name") but
-+ * no actions list; you either have the named permission
-+ * or you don't.
-+ *
-+ * <P>
-+ * The target name is the name of the runtime permission (see below). The
-+ * naming convention follows the hierarchical property naming convention.
-+ * Also, an asterisk
-+ * may appear at the end of the name, following a ".", or by itself, to
-+ * signify a wildcard match. For example: "loadLibrary.*" or "*" is valid,
-+ * "*loadLibrary" or "a*b" is not valid.
-+ * <P>
-+ * The following table lists all the possible RuntimePermission target names,
-+ * and for each provides a description of what the permission allows
-+ * and a discussion of the risks of granting code the permission.
-+ * <P>
-+ *
-+ * <table border=1 cellpadding=5 summary="permission target name,
-+ * what the target allows,and associated risks">
-+ * <tr>
-+ * <th>Permission Target Name</th>
-+ * <th>What the Permission Allows</th>
-+ * <th>Risks of Allowing this Permission</th>
-+ * </tr>
-+ *
-+ * <tr>
-+ * <td>registerBootstrapMethod.{class name}</td>
-+ * <td>Specifying a bootstrap method for invokedynamic, within a class of the given name</td>
-+ * <td>An attacker could attempt to attach a bootstrap method to a class which
-+ * has just been loaded, thus gaining control of its invokedynamic calls.</td>
-+ * </tr>
-+ *
-+ * <tr>
-+ * <td>invalidateAll</td>
-+ * <td>Force the relinking of invokedynamic call sites everywhere.</td>
-+ * <td>This could allow an attacker to slow down the system, or perhaps surface timing bugs in a dynamic language implementations, by forcing redundant relinking operations.</td>
-+ * </tr>
-+ *
-+ *
-+ * <tr>
-+ * <td>invalidateCallerClass.{class name}</td>
-+ * <td>Force the relinking of invokedynamic call sites in the given class.</td>
-+ * <td>See {@code invalidateAll}.</td>
-+ * </tr>
-+ * </table>
-+ *
-+ * @see java.security.BasicPermission
-+ * @see java.lang.SecurityManager
-+ *
-+ * @author jrose
-+ */
-+
-+public final class LinkagePermission extends BasicPermission {
-+ /**
-+ * Create a new LinkagePermission with the given name.
-+ * The name is the symbolic name of the LinkagePermission, such as
-+ * "registerBootstrapMethod", "invalidateClass.*", etc. An asterisk
-+ * may appear at the end of the name, following a ".", or by itself, to
-+ * signify a wildcard match.
-+ *
-+ * @param name the name of the LinkagePermission
-+ */
-+ public LinkagePermission(String name) {
-+ super(name);
-+ }
-+
-+ /**
-+ * Create a new LinkagePermission with the given name on the given class.
-+ * Equivalent to {@code LinkagePermission(name+"."+clazz.getName())}.
-+ *
-+ * @param name the name of the LinkagePermission
-+ * @param clazz the class affected by the permission
-+ */
-+ public LinkagePermission(String name, Class<?> clazz) {
-+ super(name + "." + clazz.getName());
-+ }
-+}
-diff --git a/src/share/projects/meth/src/java/dyn/MethodHandle.java b/src/share/projects/meth/src/java/dyn/MethodHandle.java
-new file mode 100644
---- /dev/null
-+++ b/src/share/projects/meth/src/java/dyn/MethodHandle.java
-@@ -0,0 +1,128 @@
-+/*
-+ * Copyright 2008 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. Sun designates this
-+ * particular file as subject to the "Classpath" exception as provided
-+ * by Sun in the LICENSE file that accompanied this code.
-+ *
-+ * 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.
-+ */
-+
-+package java.dyn;
-+
-+//import java.dyn.emu.*;
-+import java.dyn.hotspot.*;
-+
-+/**
-+ * A method handle is a typed reference to the entry point of a method.
-+ * <p>
-+ * Method handles are strongly typed according to signature.
-+ * They are not distinguished by method name or enclosing class.
-+ * A method handle must be invoked under a signature which exactly matches
-+ * the method handle's own type.
-+ * <p>
-+ * Every method handle confesses its type via the <code>type</code> accessor.
-+ * The structure of this type is a series of classes, one of which is
-+ * the return type of the method (or <code>void.class</code> if none).
-+ * <p>
-+ * Every method handle appears as an object containing a method named
-+ * <code>invoke</code>, whose signature exactly matches
-+ * the method handle's type.
-+ * <p>
-+ * Every call to a method handle specifies an intended method type,
-+ * which must exactly match the type of the method handle.
-+ * The call looks within the receiver object for a method
-+ * named <code>invoke</code> of the intended method type.
-+ * The call fails with a linkage error if the method does not exist,
-+ * even if there is an <code>invoke</code> method
-+ * of a closely similar signature.
-+ * <p>
-+ * The receiver object must either be of type <code>MethodHandle</code>
-+ * or else possess an <code>invoke</code> method in a public supertype
-+ * of the receiver object. In other words, invocation of method handles
-+ * is structurally typed, and will succeed as long as the receiver
-+ * contains a public method of the correct name and type.
-+ * <p>
-+ * A method handle is an unrestricted capability to call a method.
-+ * A method handle can be formed on a non-public method by a class
-+ * that has access to that method; the resulting handle can be used
-+ * in any place by any caller who gets access to it. Thus, access
-+ * checking is performed when the method handle is created, not
-+ * (as in reflection) every time it is called. Handles to non-public
-+ * methods, or in non-public classes, should generally be kept secret.
-+ * They should not be passed to untrusted code.
-+ * <p>
-+ * Bytecode in an extended JVM can directly call a method handle's
-+ * <code>invoke</code> from an <code>invokeinterface</code> instruction.
-+ * The interface type must be <code>MethodHandle</code> and the method name
-+ * must be <code>invoke</code>. The signature of the invocation must
-+ * (after linking symbolic type names) exactly match the method type
-+ * of the target method.
-+ * <p>
-+ * Bytecode in an extended JVM can directly obtain a method handle
-+ * for any accessible method from a <code>ldc</code> instruction
-+ * which refers to a <code>CONSTANT_Methodref</code> or
-+ * <code>CONSTANT_InterfaceMethodref</code> constant pool entry.
-+ * <p>
-+ * All JVMs can also use a reflective API called <code>MethodHandles</code>
-+ * for creating and calling method handles.
-+ * <p>
-+ * A method reference may refer either to a static or non-static method.
-+ * In the non-static case, the method handle type includes an explicit
-+ * receiver argument, prepended before any other arguments.
-+ * In the method handle's type, the initial receiver argument is typed
-+ * according to the class under which the method was initially requested.
-+ * (E.g., if a non-static method handle is obtained via <code>ldc</code>,
-+ * the type of the receiver is the class named in the constant pool entry.)
-+ * <p>
-+ * When a method handle to a virtual method is invoked, the method is
-+ * always looked up in the receiver.
-+ * <p>
-+ * A non-virtual method handles to a specific virtual method implementation
-+ * can also be created. These do not perform virtual lookup based on
-+ * receiver type. Such a method handle can only be created directly by
-+ * the JVM, or synthesized from bytecode that also is allowed to contain
-+ * an <code>invokespecial</code> instruction to the same method.
-+ *
-+ * @see MethodType
-+ * @see MethodHandles
-+ * @author jrose
-+ */
-+public class MethodHandle /*<T extends MethodType>*/ extends MH {
-+ // interface MethodHandle<T extends MethodType<R,A...>>
-+ // { T type(); <R,A...> public R invoke(A...); }
-+
-+ /**
-+ * Report the type of this method handle.
-+ * Every invocation of this method handle must exactly match this type.
-+ * @return the method handle type
-+ */
-+ public MethodType type() {
-+ return type; // inherited field
-+ }
-+
-+ /**
-+ * Subclasses may be in other packages, but must possess
-+ * a token which they obtained from MH with a security check.
-+ * @param token
-+ */
-+ protected MethodHandle(Access token, MethodType type) {
-+ super(token, type);
-+ }
-+
-+}
-diff --git a/src/share/projects/meth/src/java/dyn/MethodHandles.java b/src/share/projects/meth/src/java/dyn/MethodHandles.java
-new file mode 100644
---- /dev/null
-+++ b/src/share/projects/meth/src/java/dyn/MethodHandles.java
-@@ -0,0 +1,710 @@
-+package java.dyn;
-+
-+import java.util.ArrayList;
-+import sun.reflect.Reflection;
-+
-+//import java.dyn.emu.*;
-+import java.dyn.hotspot.*;
-+
-+/**
-+ * Fundamental operations and utilities for MethodHandle.
-+ * <p>
-+ * <em>API Note:</em> The matching of method types in this API cannot
-+ * be completely checked by Java's generic type system for three reasons:
-+ * <ol>
-+ * <li>Method types range over all possible arities,
-+ * from no arguments to an arbitrary number of arguments.
-+ * Generics are not variadic, and so cannot represent this.</li>
-+ * <li>Method types can specify arguments of primitive types,
-+ * which Java generic types cannot range over.</li>
-+ * <li>Method types can optionally specify varargs (ellipsis).</li>
-+ * </ol>
-+ * @author jrose
-+ */
-+public class MethodHandles {
-+
-+ private MethodHandles() { } // do not instantiate
-+
-+ private static final Access TOKEN = Access.getToken();
-+
-+ //// Method handle creation from ordinary methods.
-+
-+ /**
-+ * Produce a method handle for a static method.
-+ * The type of the method handle will be that of the method.
-+ * The method and all its argument types must be accessible to the caller.
-+ * @param defc the class from which the method is accessed
-+ * @param name the name of the method
-+ * @param type the type of the method
-+ * @return the desired method handle, or null if no such method exists
-+ */
-+ public static
-+ MethodHandle findStatic(Class<?> defc, String name, MethodType type) {
-+ Class<?> callc = Reflection.getCallerClass(2);
-+ return MH.findMethod(TOKEN, defc, name, null, type, false, callc);
-+ }
-+
-+ /**
-+ * Produce a method handle for a virtual method.
-+ * The type of the method handle will be that of the method,
-+ * with the receiver type (<code>defc</code>) prepended.
-+ * The method and all its argument types must be accessible to the caller.
-+ * <p>
-+ * When called, the handle will treat the first argument as a receiver
-+ * and dispatch on the receiver's type to determine which method
-+ * implementation to enter.
-+ * (The dispatching action is identical with that performed by an
-+ * <code>invokevirtual</code> or <code>invokeinterface</code> instruction.)
-+ * @param defc the class or interface from which the method is accessed
-+ * @param name the name of the method
-+ * @param type the type of the method, with the receiver argument omitted
-+ * @return the desired method handle, or null if no such method exists
-+ */
-+ public static
-+ MethodHandle findVirtual(Class<?> defc, String name, MethodType type) {
-+ Class<?> callc = Reflection.getCallerClass(2);
-+ return MH.findMethod(TOKEN, defc, name, defc, type, true, callc);
-+ }
-+
-+ /**
-+ * Produce an early-bound method handle for a virtual method.
-+ * The type of the method handle will be that of the method,
-+ * with the receiver type (<code>defc</code>) prepended.
-+ * The method and all its argument types must be accessible to the caller.
-+ * <p>
-+ * When called, the handle will treat the first argument as a receiver,
-+ * but will not dispatch on the receiver's type.
-+ * (This direct invocation action is identical with that performed by an
-+ * <code>invokespecial</code> instruction.)
-+ * @param defc the class or interface from which the method is accessed
-+ * @param name the name of the method
-+ * @param type the type of the method, with the receiver argument omitted
-+ * @return the desired method handle, or null if no such method exists
-+ */
-+ public static
-+ MethodHandle findSpecial(Class<?> defc, String name, MethodType type) {
-+ Class<?> callc = Reflection.getCallerClass(2);
-+ return MH.findMethod(TOKEN, defc, name, defc, type, false, callc);
-+ }
-+
-+ /**
-+ * Make a direct method handle to <i>m</i>, if the current caller has permission.
-+ * If <i>m</i> is non-static, the receiver argument is treated as an initial argument.
-+ * If <i>m</i> is virtual, overriding is respected on every call.
-+ * Unlike the Core Reflection API, exceptions are <em>not</em> wrapped.
-+ * The type of the method handle will be that of the method,
-+ * with the receiver type prepended (but only if it is non-static).
-+ * If the method's <code>accessible</code> flag is not set,
-+ * access checking is performed immediately on behalf of the caller.
-+ * If <i>m</i> is not public, do not share the resulting handle with untrusted callers.
-+ * @param m the reflected method
-+ * @return a method handle which can invoke the reflected method
-+ */
-+ public static
-+ MethodHandle unreflect(java.lang.reflect.Method m) {
-+ throw new UnsupportedOperationException("NYI");
-+ }
-+
-+ /**
-+ * Produce a method handle for a reflected method.
-+ * It will bypass checks for overriding methods on the receiver,
-+ * as if by the <code>invokespecial</code> instruction.
-+ * The type of the method handle will be that of the method,
-+ * with the receiver type prepended.
-+ * If the method's <code>accessible</code> flag is not set,
-+ * access checking is performed immediately on behalf of the caller,
-+ * as if <code>invokespecial</code> instruction were being linked.
-+ * @param m the reflected method
-+ * @return a method handle which can invoke the reflected method
-+ */
-+ public static
-+ MethodHandle unreflectSpecial(java.lang.reflect.Method m) {
-+ throw new UnsupportedOperationException("NYI");
-+ }
-+
-+ /**
-+ * Produce a method handle giving read access to a reflected field.
-+ * The type of the method handle will have a return type of the field's
-+ * value type. Its sole argument will be the field's containing class
-+ * (but only if it is non-static).
-+ * If the method's <code>accessible</code> flag is not set,
-+ * access checking is performed immediately on behalf of the caller.
-+ * @param f the reflected field
-+ * @return a method handle which can load values from the reflected field
-+ */
-+ public static
-+ MethodHandle unreflectGetter(java.lang.reflect.Field f) {
-+ throw new UnsupportedOperationException("NYI");
-+ }
-+
-+ /**
-+ * Produce a method handle giving write access to a reflected field.
-+ * The type of the method handle will have a void return type.
-+ * Its last argument will be the field's value type.
-+ * Its other argument will be the field's containing class
-+ * (but only if it is non-static).
-+ * If the method's <code>accessible</code> flag is not set,
-+ * access checking is performed immediately on behalf of the caller.
-+ * @param f the reflected field
-+ * @return a method handle which can store values into the reflected field
-+ */
-+ public static
-+ MethodHandle unreflectSetter(java.lang.reflect.Field f) {
-+ throw new UnsupportedOperationException("NYI");
-+ }
-+
-+ /// method handle modification (creation from other method handles)
-+
-+ /**
-+ * Return the given method handle unchanged, after ensuring that
-+ * its type is equal to the given type.
-+ * @param mh
-+ * @param type
-+ * @return the original method handle
-+ */
-+ static <M extends MethodHandle>
-+ M castType(M mh, MethodType type) {
-+ MethodType mhType = mh.type();
-+ if (!type.equals(mhType))
-+ throw new ClassCastException(mhType.toString());
-+ return mh;
-+ }
-+
-+ /**
-+ * Perform value checking, exactly as if for an adapted method handle.
-+ * It is assumed that the given value is either null, of type T0,
-+ * or (if T0 is primitive) of the wrapper type corresponding to T0.
-+ * The following checks and conversions are made:
-+ * <ul>
-+ * <li>If T0 and T1 are references, then a cast to T1 is applied.
-+ * (The types do not need to be related in any particular way.)
-+ * <li>If T0 and T1 are primitives, then a widening or narrowing
-+ * conversion is applied, if one exists.
-+ * <li>If T0 is a primitive and T1 a reference, and
-+ * T0 has a wrapper type TW, a boxing conversion to TW is applied,
-+ * possibly followed by a reference conversion.
-+ * T1 must be TW or a supertype.
-+ * <li>If T0 is a reference and T1 a primitive, and
-+ * T1 has a wrapper type TW, an unboxing conversion is applied,
-+ * possibly preceded by a reference conversion.
-+ * T0 must be TW or a supertype.
-+ * <li>If T1 is void, the return value is discarded
-+ * <li>If T0 is void and T1 a reference, a null value is introduced.
-+ * <li>If T0 is void and T1 a primitive, a zero value is introduced.
-+ * </ul>
-+ * If the value is discarded, null will be returned.
-+ * @param valueType
-+ * @param value
-+ * @return the value, converted if necessary
-+ * @throws java.lang.ClassCastException if a cast fails
-+ */
-+ static
-+ Object checkValue(Class<?> T0, Class<?> T1, Object value)
-+ throws ClassCastException
-+ {
-+ if (T0 == T1) {
-+ // no conversion needed
-+ return value;
-+ }
-+ boolean prim0 = T0.isPrimitive(), prim1 = T1.isPrimitive();
-+ Class<?> TW;
-+ if (!prim0) {
-+ if (!prim1) {
-+ return T1.cast(T0.cast(value));
-+ }
-+ // convert reference to primitive by unboxing
-+ TW = Wrappers.asWrapperType(T0);
-+ return T1.cast(TW.cast(value));
-+ }
-+ if (!prim1) {
-+ // convert primitive to reference type by boxing
-+ TW = Wrappers.asWrapperType(T1);
-+ return TW.cast(T0.cast(value));
-+ }
-+ // convert primitive to primitive; this requires a real value change
-+ if (value == null)
-+ return Wrappers.zeroValue(T1);
-+ // convert non-Number primitives to Integer:
-+ if (value instanceof Character) {
-+ char ch = (char) (Character) value;
-+ value = Integer.valueOf(ch);
-+ if (T1 == Integer.class)
-+ return value;
-+ } else if (value instanceof Boolean) {
-+ boolean z = (boolean) (Boolean) value;
-+ value = Integer.valueOf(z ? 1 : 0);
-+ if (T1 == Integer.class)
-+ return value;
-+ }
-+ Number numval = (Number) value;
-+ switch (Wrappers.basicTypeChar(T1)) {
-+ case 'Z': return (numval.intValue() != 0);
-+ case 'B': return numval.byteValue();
-+ case 'C': return (char) numval.intValue();
-+ case 'S': return numval.shortValue();
-+ case 'I': return numval.intValue();
-+ case 'J': return numval.longValue();
-+ case 'F': return numval.floatValue();
-+ case 'D': return numval.doubleValue();
-+ }
-+ return null;
-+ }
-+
-+ static
-+ Object checkValue(Class<?> T1, Object value)
-+ throws ClassCastException
-+ {
-+ return checkValue(T1, value.getClass(), value);
-+ }
-+
-+ /**
-+ * Produce a method handle which calls the original method handle,
-+ * after performing general-purpose argument list conversions.
-+ * The resulting method handle is guaranteed to confess a type
-+ * which is equal to the desired newType.
-+ * <p>
-+ * An <i>outgoing argument</i> is one which will be passed to the
-+ * original method handle. An <i>incoming argument</i> is one which
-+ * will be passed to the new method handle. The old and
-+ * new method types are determined by the original method handle's
-+ * <code>getType</code> operation and the <code>newType</code> parameter,
-+ * respectively.
-+ * <p>
-+ * The arguments string must specify the data source for every outgoing
-+ * argument. The string contains zero or more short char sequences
-+ * called <i>argument descriptors</i>, each of which determines
-+ * how the corresponding outgoing parameter is supplied with an incoming
-+ * argument, how an extra check is made during the call, or how a return
-+ * value is to be produced.
-+ * <p>
-+ * An argument descriptor must have one of the following forms:
-+ * <ul>
-+ * <li>$<i>N</i> &mdash; the <i>N</i>th incoming argument ($0 is first)
-+ * <li>$<i>N</i>/<i>I</i> &mdash; the <i>I</i>th array element of $<i>N</i>
-+ * <li>$V &mdash; the values argument passed to this method
-+ * <li>$V/<i>I</i> &mdash; the <i>I</i>th array element of $V
-+ * <li>!$<i>N</i>/<i>L</i> &mdash; Array length cutoff:
-+ * The incoming array argument <i>N</i> must be exactly of length L.
-+ * (If L is zero, the array may be null also.)
-+ * <li>{<i>D...</i>} &mdash; This is an array argument descriptor;
-+ * a sequence of one or more argument descriptors
-+ * is collected into an array. The brackets may not be nested.
-+ * <li>{<i>...</i>*$<i>N</i>} &mdash; An array argument
-+ * specifier may end with a starred argument reference,
-+ * meaning that it and all remaining arguments are included
-+ * in the tail of the outgoing argument array.
-+ * <li>{<i>...</i>*<i>D</i>/<i>I</i>} &mdash; An array argument
-+ * specifier may end with a starred element reference,
-+ * meaning that all remaining elements of the incoming argument
-+ * or value array are included in the tail of the
-+ * outgoing argument array. (As a limiting case,
-+ * if <i>I</i> is the incoming array length, no additional
-+ * elements are added to the outgoing array.)
-+ * <li>$X0 &mdash; a zero or null of the expected argument type
-+ * <li>$X<i>X</i> &mdash; an integer hexadecimal constant is passed
-+ * <li>$N &mdash; the new method handle itself is passed
-+ * <li>$M &mdash; the original method handle itself is passed
-+ * <li>*<i>D</i> &mdash; The final argument descriptor may be
-+ * starred if it is an incoming argument or element descriptor,
-+ * meaning that all remaining outgoing arguments are
-+ * taken from that argument (or element) onward.
-+ * (E.g., "*$1" means pass all arguments except the first,
-+ * and "*$V/0" means pass all elements of the value array.)
-+ * <li>=<i>D</i> &mdash; An equal sign introduces an optional
-+ * return descriptor. The <i>N</i>th incoming argument is saved
-+ * and used as the final return value from the new method handle.
-+ * Any argument descriptor can be used after the equal sign.
-+ * This descriptor must come last, if it appears at all.
-+ * <li><i>...</i>*<i>D</i>=<i>D</i> &mdash; Star and equal sign
-+ * can appear together; in this case the return descriptor is last.
-+ * <li>commas and whitespace are ignored before and after descriptors
-+ * </ul>
-+ * All values N, I, L must be decimal numerals in the range 0..255.
-+ * For outgoing arrays, if L is zero, a constant zero-length array
-+ * may be passed instead of a new array.
-+ * <p>
-+ * Any argument array can be spread or unspread, though the
-+ * Java varargs convention treats only the final argument this way.
-+ * Spreading and unspreading respects the element type of the
-+ * affected array(s), performing element-by-element conversion
-+ * if necessary.
-+ * <p>
-+ * There must be exactly enough argument descriptors (not counting
-+ * a final return descriptor) to supply every
-+ * outgoing argument to the old method handle.
-+ * <p>
-+ * If an equals sign is present, the following specifier is not for
-+ * an outgoing argument, but rather for the ultimate return value
-+ * produced by the new method handle. In that case any return
-+ * value produced by the original method is discarded.
-+ * (This may be used to force an adapted method handle to return
-+ * a fixed value, or a selected argument, such as the receiver.)
-+ * <p>
-+ * Additional conversions are applied as needed to ensure that
-+ * the outgoing argument types and final return type are respected.
-+ * These value-oriented conversions perform casting, boxing,
-+ * and unboxing, exactly as described in {@link #convertArguments}.
-+ * <p>
-+ * If an array is created (because a curly bracket '{' is present)
-+ * the type of the new array is exactly that specified by the
-+ * corresponding outgoing argument or return type.
-+ *
-+ * @param mh the method handle to invoke after the argument is prepended
-+ * @param newType the expected type of the new method handle
-+ * @param arguments descriptions of individual arguments to pass to mh
-+ * @param values the argument to prepend
-+ * @return a new method handle which converts the argument list,
-+ * before calling the original method handle
-+ */
-+ static
-+ MethodHandle adaptArguments(MethodHandle mh, MethodType newType,
-+ String arguments, Object values) {
-+ throw new UnsupportedOperationException("NYI");
-+ }
-+
-+ /**
-+ * Produce a method handle which adapts the type of the
-+ * given method handle to a new type, by pairwise argument conversion.
-+ * The fourth and following arguments are collected into a values array
-+ * and passed to the main overloading of {@link #adaptArguments}.
-+ */
-+ static
-+ MethodHandle adaptArguments(MethodHandle mh, MethodType newType,
-+ String arguments, Object... values) {
-+ return adaptArguments(mh, newType, arguments, (Object) values);
-+ }
-+
-+ /**
-+ * Produce a method handle which adapts the type of the
-+ * given method handle to a new type, by pairwise argument conversion.
-+ * The missing value argument defaults to null, which is passed to
-+ * the main overloading of {@link #adaptArguments}.
-+ */
-+ static
-+ MethodHandle adaptArguments(MethodHandle mh, MethodType newType,
-+ String arguments) {
-+ return adaptArguments(mh, newType, arguments, (Object) null);
-+ }
-+
-+ /**
-+ * Produce a method handle which adapts the type of the
-+ * given method handle to a new type, by pairwise argument conversion.
-+ * The original type and new type must have the same number of
-+ * arguments.
-+ * The resulting method handle is guaranteed to confess a type
-+ * which is equal to the desired new type.
-+ * <p>
-+ * If the original type and new type are equal, returns mh.
-+ * <p>
-+ * The following conversions are applied as needed both to
-+ * arguments and return types. If T0 and T1 are differing
-+ * old and new parameter types (or new and old return types),
-+ * then one of the following conversions is applied if possible:
-+ * <ul>
-+ * <li>If T0 and T1 are references, then a cast to T1 is applied.
-+ * (The types do not need to be related in any particular way.)
-+ * <li>If T0 and T1 are primitives, then a Java casting
-+ * conversion (JLS 5.5) is applied, if one exists.
-+ * <li>If T0 and T1 are primitives and one is boolean and the other
-+ * is one of byte, short, char, or int, then zero and non-zero
-+ * values are interconverted with false and true, respectively.
-+ * (This follows the usage of the bytecode verifier.)
-+ * <li>If T0 is a primitive and T1 a reference, a boxing
-+ * conversion is applied if one exists, possibly followed by
-+ * an reference conversion to a superclass.
-+ * T1 must be a wrapper class or a supertype of one.
-+ * If T1 is a wrapper class, T0 is converted if necessary
-+ * to T1's primitive type by one of the preceding conversions.
-+ * Otherwise, T0 is boxed, and its wrapper converted to T1.
-+ * <li>If T0 is a reference and T1 a primitive, an unboxing
-+ * conversion is applied if one exists, possibly preceded by
-+ * a reference conversion to a wrapper class.
-+ * T0 must be a wrapper class or a supertype of one.
-+ * If T0 is a wrapper class, its primitive value is converted
-+ * if necessary to T1 by one of the preceding conversions.
-+ * Otherwise, T0 is converted directly to the wrapper type for T1,
-+ * which is then unboxed.
-+ * <li>If T1 is void, the return value is discarded
-+ * <li>If T0 is void and T1 a reference, a null value is introduced.
-+ * <li>If T0 is void and T1 a primitive, a zero value is introduced.
-+ * </ul>
-+ * @param mh the method handle to invoke after arguments are retyped
-+ * @param newType the expected type of the new method handle
-+ * @return
-+ */
-+ public static
-+ MethodHandle convertArguments(MethodHandle mh, MethodType newType) {
-+ MethodType oldType = mh.type();
-+ if (oldType.equals(newType))
-+ return mh;
-+ return adaptArguments(mh, newType, "*$0");
-+ }
-+
-+ /**
-+ * Produce a method handle which adapts the type of the
-+ * given method handle to a new type, by spreading the final argument.
-+ * The resulting method handle is guaranteed to confess a type
-+ * which is equal to the desired new type.
-+ * <p>
-+ * The final parameter type of the new type must be an array type T[].
-+ * This is the type of what is called the <i>spread</i> argument.
-+ * All other arguments of the new type are called <i>ordinary</i> arguments.
-+ * <p>
-+ * The ordinary arguments of the new type are pairwise converted
-+ * to the initial parameter types of the old type, according to the
-+ * rules in {@link #convertArguments}.
-+ * Any additional arguments in the old type
-+ * are converted from the array element type T,
-+ * again according to the rules in {@link #convertArguments}.
-+ * The return value is converted according likewise.
-+ * <p>
-+ * The call verifies that the spread argument is in fact an array
-+ * of exactly the type length, i.e., the excess number of
-+ * arguments in the old type over the ordinary arguments in the new type.
-+ * If there are no excess arguments, the spread argument is also
-+ * allowed to be null.
-+ * @param mh the method handle to invoke after the argument is prepended
-+ * @param newType the expected type of the new method handle
-+ * @return a new method handle which spreads its final argument,
-+ * before calling the original method handle
-+ */
-+ public static
-+ MethodHandle spreadArguments(MethodHandle mh, MethodType newType) {
-+ MethodType oldType = mh.type();
-+ int inargs = newType.parameterCount();
-+ int outargs = oldType.parameterCount();
-+ int spreadPos = inargs - 1;
-+ int numSpread = (outargs - spreadPos);
-+ if (spreadPos < 0 || numSpread < 0)
-+ throw new IllegalArgumentException("wrong number of arguments");
-+ StringBuilder arguments = new StringBuilder(inargs * 4 + 16);
-+ // examples:
-+ // new(T[]) => old(x,y,z) "!$0/3 *$0/0"
-+ // new(a,T[]) => old(a,x,y) "$0 !$1/2 *$1/0"
-+ // new(a,b,T[]) => old(a,b) "$0 $1 !$2/0"
-+ for (int i = 0; i < spreadPos; i++) {
-+ arguments.append("$").append(i);
-+ }
-+ arguments.append("!$").append(spreadPos).append("/").append(numSpread);
-+ if (numSpread != 0) {
-+ arguments.append("*$").append(spreadPos).append("/0");
-+ }
-+ return adaptArguments(mh, newType, arguments.toString());
-+ }
-+
-+ /**
-+ * Produce a method handle which adapts the type of the
-+ * given method handle to a new type, by collecting a series of
-+ * trailing arguments into an array.
-+ * The resulting method handle is guaranteed to confess a type
-+ * which is equal to the desired new type.
-+ * <p>
-+ * This method is inverse to {@link spreadArguments}.
-+ * The final parameter type of the old type must be an array type T[],
-+ * which is the type of what is called the <i>spread</i> argument.
-+ * The trailing arguments of the new type which correspond to
-+ * the spread argument are all converted to type T and collected
-+ * into an array before the original method is called.
-+ * @param mh the method handle to invoke after the argument is prepended
-+ * @param newType the expected type of the new method handle
-+ * @return a new method handle which collects some trailings argument
-+ * into an array, before calling the original method handle
-+ */
-+ public static
-+ MethodHandle collectArguments(MethodHandle mh, MethodType newType) {
-+ MethodType oldType = mh.type();
-+ int inargs = newType.parameterCount();
-+ int outargs = oldType.parameterCount();
-+ int collectPos = outargs - 1;
-+ int numCollect = (inargs - collectPos);
-+ if (collectPos < 0 || numCollect < 0)
-+ throw new IllegalArgumentException("wrong number of arguments");
-+ StringBuilder arguments = new StringBuilder(inargs * 4 + 16);
-+ // examples:
-+ // new(x,y,z) => old(T[]) "{*$0}"
-+ // new(a,x,y) => old(a,T[]) "$0 {*$1}"
-+ // new(a,b) => old(a,b,T[]) "$0 $1 {}"
-+ for (int i = 0; i < collectPos; i++) {
-+ arguments.append("$").append(i);
-+ }
-+ if (numCollect == 0)
-+ arguments.append("{}");
-+ else
-+ arguments.append("{*$").append(collectPos).append("}");
-+ return adaptArguments(mh, newType, arguments.toString());
-+ }
-+
-+ /**
-+ * Produce a method handle which calls the original method handle,
-+ * after inserting the given argument as the first argument.
-+ * The type of the new method handle will drop the first argument
-+ * type from the original handle's type.
-+ * <p>
-+ * Equivalent to <code>insertArgument(mh, value, 0)</code>.
-+ */
-+ public static
-+ MethodHandle insertArgument(MethodHandle mh, Object value) {
-+ return insertArgument(mh, value, 0);
-+ }
-+
-+ /**
-+ * Produce a method handle which calls the original method handle,
-+ * after appending the given argument as the final argument.
-+ * The type of the new method handle will drop the last argument
-+ * type from the original handle's type.
-+ * <p>
-+ * Equivalent to <code>insertArgument(mh, value, N)</code>,
-+ * where <i>N</i> is the number of arguments to <i>mh</i>.
-+ */
-+ public static
-+ MethodHandle appendArgument(MethodHandle mh, Object value) {
-+ return insertArgument(mh, value, mh.type().parameterCount());
-+ }
-+
-+ /**
-+ * Produce a method handle which calls the original method handle,
-+ * after inserting the given argument at the given position.
-+ * The type of the new method handle will drop the corresponding argument
-+ * type from the original handle's type.
-+ * <p>
-+ * The given argument object must match the dropped argument type.
-+ * If the dropped argument type is a primitive, the argument object
-+ * must be a wrapper, and is unboxed to produce the primitive.
-+ * <p>
-+ * The <i>pos</i> may range between zero and <i>N</i> (inclusively),
-+ * where <i>N</i> is the number of argument types in <i>mh</i>,
-+ * meaning to insert the new argument as the first or last (respectively),
-+ * or somewhere in between.
-+ * @param mh the method handle to invoke after the argument is inserted
-+ * @param value the argument to insert
-+ * @param pos where to insert the argument (zero for the first)
-+ * @return a new method handle which inserts an additional argument,
-+ * before calling the original method handle
-+ */
-+ public static
-+ MethodHandle insertArgument(MethodHandle mh, Object value, int pos) {
-+ MethodType oldType = mh.type();
-+ ArrayList<Class<?>> ptypes =
-+ new ArrayList<Class<?>>(oldType.parameterList());
-+ int outargs = oldType.parameterCount();
-+ int inargs = outargs - 1;
-+ if (pos < 0 || pos >= outargs)
-+ throw new IllegalArgumentException("no argument type to append");
-+ Class<?> valueType = ptypes.remove(pos);
-+ value = checkValue(valueType, value);
-+ MethodType newType = MethodType.make(oldType.returnType(), ptypes);
-+ String arguments;
-+ switch (pos) {
-+ case 0: arguments = inargs == 0 ? "$V" : "$V*$0"; break;
-+ case 1: arguments = inargs == 1 ? "$0$V" : "$0$V*$1"; break;
-+ default:
-+ StringBuilder sb = new StringBuilder(outargs * 4 + 16);
-+ for (int i = 0; i < outargs; i++) {
-+ if (i < pos) {
-+ sb.append("$").append(i);
-+ } else if (i == pos) {
-+ sb.append("$V");
-+ } else {
-+ sb.append("*$").append(i-1);
-+ break;
-+ }
-+ }
-+ arguments = sb.toString();
-+ }
-+ return adaptArguments(mh, newType, arguments, value);
-+ }
-+
-+ /**
-+ * Produce a method handle which calls the original method handle,
-+ * after dropping the given argument at the given position.
-+ * The type of the new method handle will insert the given argument
-+ * type, at that position, into the original handle's type.
-+ * <p>
-+ * The <i>pos</i> may range between zero and <i>N-1</i>,
-+ * where <i>N</i> is the number of argument types in <i>mh</i>,
-+ * meaning to drop the first or last argument (respectively),
-+ * or an argument somewhere in between.
-+ * @param mh the method handle to invoke after the argument is dropped
-+ * @param valueType the type of the argument to drop
-+ * @param pos which argument to drop (zero for the first)
-+ * @return a new method handle which drops an argument of the given type,
-+ * before calling the original method handle
-+ */
-+ public static
-+ MethodHandle dropArgument(MethodHandle mh, Class<?> valueType, int pos) {
-+ MethodType oldType = mh.type();
-+ ArrayList<Class<?>> ptypes =
-+ new ArrayList<Class<?>>(oldType.parameterList());
-+ int outargs = oldType.parameterCount();
-+ int inargs = outargs + 1;
-+ if (pos < 0 || pos >= inargs)
-+ throw new IllegalArgumentException("no argument type to remove");
-+ ptypes.add(pos, valueType);
-+ MethodType newType = MethodType.make(oldType.returnType(), ptypes);
-+ String arguments;
-+ switch (pos) {
-+ case 0: arguments = inargs == 0 ? "": "*$1"; break;
-+ case 1: arguments = inargs == 1 ? "$0": "$0*$2"; break;
-+ default:
-+ if (pos == outargs) { arguments = "*$0"; break; }
-+ StringBuilder sb = new StringBuilder(outargs * 4 + 16);
-+ for (int i = 0; i < outargs; i++) {
-+ if (i < pos) {
-+ sb.append("$").append(i);
-+ } else if (i > pos) {
-+ sb.append("*$").append(i);
-+ break;
-+ }
-+ }
-+ arguments = sb.toString();
-+ }
-+ return adaptArguments(mh, newType, arguments);
-+ }
-+
-+ /// standard method handles
-+
-+ /**
-+ * Identity function.
-+ * @param x an arbitrary reference value
-+ * @return the same value x
-+ */
-+ public static <T>
-+ T identity(T x) {
-+ return x;
-+ }
-+
-+ /**
-+ * A method handle for {@link identity}
-+ */
-+ public static
-+ MethodHandle identityMethod() {
-+ if (IDENTITY == null)
-+ IDENTITY = findStatic(MethodHandle.class, "identity", IDENTITY_TYPE);
-+ return IDENTITY;
-+ }
-+ private static
-+ MethodHandle IDENTITY;
-+ private static final
-+ MethodType IDENTITY_TYPE = MethodType.make(Object.class, Object.class);
-+
-+ /**
-+ * Empty function.
-+ */
-+ public static
-+ void empty() {
-+ }
-+
-+ /**
-+ * A method handle for {@link empty}
-+ */
-+ public static
-+ MethodHandle emptyMethod() {
-+ if (EMPTY == null)
-+ EMPTY = findStatic(MethodHandle.class, "empty", EMPTY_TYPE);
-+ return EMPTY;
-+ }
-+ private static
-+ MethodHandle EMPTY;
-+ private static final
-+ MethodType EMPTY_TYPE = MethodType.make(void.class);
-+}
-diff --git a/src/share/projects/meth/src/java/dyn/MethodType.java b/src/share/projects/meth/src/java/dyn/MethodType.java
-new file mode 100644
---- /dev/null
-+++ b/src/share/projects/meth/src/java/dyn/MethodType.java
-@@ -0,0 +1,553 @@
-+/*
-+ * Copyright 2008 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. Sun designates this
-+ * particular file as subject to the "Classpath" exception as provided
-+ * by Sun in the LICENSE file that accompanied this code.
-+ *
-+ * 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.
-+ */
-+
-+package java.dyn;
-+
-+import java.lang.reflect.Method;
-+import java.lang.reflect.Modifier;
-+import java.util.ArrayList;
-+import java.util.Arrays;
-+import java.util.Collections;
-+import java.util.HashMap;
-+import java.util.List;
-+
-+/**
-+ * Run-time token used to match call sites with method handles.
-+ * The structure is a return type accompanied by any number of parameter types.
-+ * The types (primitive, void, and reference) are represented by Class objects.
-+ * All instances of <code>MethodType</code> are immutable.
-+ * Two instances are completely interchangeable if they compare equal.
-+ * Equality depends exactly on the return and parameter types, plus the varargs bit.
-+ * <p>
-+ * This type can be created only by factory methods, which manage interning.
-+ *
-+ * @author jrose
-+ */
-+public final
-+class MethodType {
-+ final Class<?> rtype;
-+ final Class<?>[] ptypes;
-+ MethodTypeForm form; // erased form, plus cached data about primitives
-+ MethodType wrapAlt; // alternative wrapped/unwrapped version
-+
-+ private MethodType(Class<?> rtype, Class<?>[] ptypes, boolean varargs) {
-+ this.rtype = rtype;
-+ this.ptypes = ptypes;
-+ if (!varargs) {
-+ this.form = MethodTypeForm.FAKE[0];
-+ } else {
-+ this.form = MethodTypeForm.FAKE[1];
-+ checkVarargs();
-+ }
-+ assert(this.isVarArgs() == varargs);
-+ }
-+
-+ private void checkVarargs() {
-+ if (ptypes.length == 0 || !ptypes[ptypes.length-1].isArray())
-+ throw new IllegalArgumentException("not varargs: "+this);
-+ }
-+
-+ static final HashMap<MethodType,MethodType> internTable
-+ = new HashMap<MethodType, MethodType>();
-+
-+ static final Class<?>[] NO_PTYPES = {};
-+
-+ /** Find or create an instance of the given method type.
-+ * @param rtype the return type
-+ * @param ptypes the parameter types
-+ * @return the interned method type with the given parts
-+ */
-+ public static
-+ MethodType make(Class<?> rtype, Class<?>[] ptypes) {
-+ return makeImpl(rtype, ptypes, false, false);
-+ }
-+
-+ /** Find or create an instance of the given method type.
-+ * @param rtype the return type
-+ * @param ptypes the parameter types
-+ * @param varargs whether the method type will be varargs
-+ * @return the interned method type with the given parts
-+ * @throws IllegalArgumentException if varargs is true and the last parameter type is not an array
-+ */
-+ public static
-+ MethodType make(Class<?> rtype, Class<?>[] ptypes, boolean varargs) {
-+ return makeImpl(rtype, ptypes, varargs, false);
-+ }
-+
-+ /** Convenience method for {@link #make(java.lang.Class, java.lang.Class<?>[])}. */
-+ public static
-+ MethodType make(Class<?> rtype, List<Class<?>> ptypes) {
-+ return makeImpl(rtype, ptypes.toArray(NO_PTYPES), false, true);
-+ }
-+
-+ /** Convenience method for {@link #make(java.lang.Class, java.lang.Class<?>[])}. */
-+ public static
-+ MethodType make(Class<?> rtype, Class<?> ptype0, Class<?>... ptypes) {
-+ return makeImpl(rtype, append(ptype0, ptypes), false, true);
-+ }
-+
-+ /** Convenience method for {@link #make(java.lang.Class, java.lang.Class<?>[])}.
-+ * The resulting method has no parameter types.
-+ */
-+ public static
-+ MethodType make(Class<?> rtype) {
-+ return makeImpl(rtype, NO_PTYPES, false, true);
-+ }
-+
-+ /** Convenience method for {@link #make(java.lang.Class, java.lang.Class<?>[])}.
-+ * The resulting method has the single given parameter type.
-+ */
-+ public static
-+ MethodType make(Class<?> rtype, Class<?> ptype0) {
-+ return makeImpl(rtype, new Class<?>[]{ ptype0 }, false, true);
-+ }
-+
-+ /** Convenience method for {@link #make(java.lang.Class, java.lang.Class<?>[])}.
-+ * The resulting method has the same parameter types as {@code ptypes},
-+ * and the specified return type.
-+ */
-+ public static
-+ MethodType make(Class<?> rtype, MethodType ptypes) {
-+ return makeImpl(rtype, ptypes.ptypes, false, true);
-+ }
-+
-+ /**
-+ * Sole factory method to find or create an interned method type.
-+ * @param rtype desired return type
-+ * @param ptypes desired parameter types
-+ * @param varargs whether the method type will be varargs
-+ * @param trusted whether the ptypes can be used without cloning
-+ * @return the unique method type of the desired structure
-+ */
-+ static
-+ MethodType makeImpl(Class<?> rtype, Class<?>[] ptypes, boolean varargs, boolean trusted) {
-+ MethodType mt1 = new MethodType(rtype, ptypes, varargs);
-+ MethodType mt0;
-+ synchronized (internTable) {
-+ mt0 = internTable.get(mt1);
-+ if (mt0 != null)
-+ return mt0;
-+ }
-+ if (!trusted)
-+ // defensively copy the array passed in by the user
-+ ptypes = ptypes.clone();
-+ // promote the object to the Real Thing, and reprobe
-+ mt1.form = MethodTypeForm.findForm(mt1, varargs);
-+ assert(mt1.isVarArgs() == varargs);
-+ synchronized (internTable) {
-+ mt0 = internTable.get(mt1);
-+ if (mt0 != null)
-+ return mt0;
-+ internTable.put(mt1, mt1);
-+ }
-+ return mt1;
-+ }
-+
-+ /** Convenience method for {@link #make(java.lang.Class, java.lang.Class<?>[])}.
-+ * Find or create an instance (interned) of the given method type.
-+ * <p>
-+ * <em>Note:</em> Since method handles are created in the system class loader,
-+ * this routine will attempt to install class loader constraints
-+ * between the system loader and the given loader, for each name
-+ * found in the signature. If these constraints cannot be created,
-+ * this routine will throw a linkage error.
-+ * @param bytecodeSignature a bytecode-level signature string "(T...)T"
-+ * @param loader the class loader in which to look up the types
-+ * @return a method type matching the bytecode-level signature
-+ */
-+ public static MethodType make(String bytecodeSignature, ClassLoader loader) {
-+ if (loader == null)
-+ loader = ClassLoader.getSystemClassLoader();
-+ String str = bytecodeSignature;
-+ int[] i = {0};
-+ ArrayList<Class<?>> ptypes = new ArrayList<Class<?>>();
-+ if (i[0] < str.length() && str.charAt(i[0]) == '(') {
-+ ++i[0]; // skip '('
-+ while (i[0] < str.length() && str.charAt(i[0]) != ')') {
-+ Class<?> pt = parseSig(str, i, loader);
-+ if (pt == null || pt == void.class)
-+ parseError(str, "bad argument type");
-+ ptypes.add(pt);
-+ }
-+ ++i[0]; // skip ')'
-+ }
-+ Class<?> rtype = parseSig(str, i, loader);
-+ if (rtype == null || i[0] != str.length())
-+ parseError(str, "bad return type");
-+ return make(rtype, ptypes);
-+ }
-+
-+ /** Create a bytecode signature representation of the type.
-+ * @return the bytecode signature representation
-+ */
-+ public String toBytecodeString() {
-+ StringBuilder sb = new StringBuilder();
-+ sb.append('(');
-+ for (Class<?> pt : ptypes)
-+ unparseSig(pt, sb);
-+ sb.append(')');
-+ unparseSig(rtype, sb);
-+ return sb.toString();
-+ }
-+
-+ static private void parseError(String str, String msg) {
-+ throw new IllegalArgumentException("bad signature: "+str+": "+msg);
-+ }
-+
-+ static private Class<?> parseSig(String str, int[] i, ClassLoader loader) {
-+ if (i[0] == str.length()) return null;
-+ char c = str.charAt(i[0]++);
-+ if (c == 'L') {
-+ int beg = i[0], end = str.indexOf(';', beg);
-+ if (end < 0) return null;
-+ i[0] = end+1;
-+ String name = str.substring(beg, end).replace('/', '.');
-+ try {
-+ // FIXME: Need loader constraints here?
-+ return loader.loadClass(name);
-+ } catch (ClassNotFoundException ex) {
-+ parseError(str, ex.toString());
-+ return null;
-+ }
-+ } else if (c == '[') {
-+ Class<?> t = parseSig(str, i, loader);
-+ if (t != null)
-+ t = java.lang.reflect.Array.newInstance(t, 0).getClass();
-+ return t;
-+ } else {
-+ return Wrappers.basicTypeFromChar(c);
-+ }
-+ }
-+
-+ private void unparseSig(Class<?> t, StringBuilder sb) {
-+ char c = Wrappers.basicTypeChar(t);
-+ if (c != 'L') {
-+ sb.append(c);
-+ } else {
-+ boolean lsemi = (!t.isArray());
-+ if (lsemi) sb.append('L');
-+ sb.append(t.getName().replace('.', '/'));
-+ if (lsemi) sb.append(';');
-+ }
-+ }
-+
-+
-+ private static final MethodType[] objectOnlyTypes = new MethodType[20];
-+
-+ /**
-+ * Convenience method for {@link #make(java.lang.Class, java.lang.Class<?>[], boolean)}.
-+ * All parameters and the return type will be Object, except the final varargs parameter if any.
-+ * @param objectArgCount number of parameters (excluding the varargs parameter if any)
-+ * @param varargs whether there will be a varargs parameter
-+ * @return a totally generic method type, given only its count of parameters and varargs.
-+ */
-+ public static
-+ MethodType makeGeneric(int objectArgCount, boolean varargs) {
-+ MethodType mt;
-+ int ivarargs = (!varargs ? 0 : 1);
-+ int ootIndex = objectArgCount*2 + ivarargs;
-+ if (ootIndex < objectOnlyTypes.length) {
-+ mt = objectOnlyTypes[ootIndex];
-+ if (mt != null) return mt;
-+ }
-+ Class<?>[] ptypes = new Class<?>[objectArgCount + ivarargs];
-+ Arrays.fill(ptypes, Object.class);
-+ if (ivarargs != 0) ptypes[objectArgCount] = Object[].class;
-+ mt = makeImpl(Object.class, ptypes, varargs, true);
-+ if (ootIndex < objectOnlyTypes.length) {
-+ objectOnlyTypes[ootIndex] = mt; // cache it here also!
-+ }
-+ return mt;
-+ }
-+
-+ /**
-+ * Convenience method for {@link #makeGeneric(int, boolean)}, defaulting {@code varargs} to false.
-+ */
-+ public static
-+ MethodType makeGeneric(int objectArgCount) {
-+ return makeGeneric(objectArgCount, false);
-+ }
-+
-+ /** Convenience method for {@link #make(java.lang.Class, java.lang.Class<?>[], boolean)}.
-+ * @param refm a reflective method
-+ * @return the type (as for a {@link MethodHandle}) of that method
-+ */
-+ public static
-+ MethodType make(Method refm) {
-+ Class<?> rt = refm.getReturnType();
-+ Class<?>[] pts = refm.getParameterTypes();
-+ if (!Modifier.isStatic(refm.getModifiers()))
-+ // implicit initial parameter is the receiver type
-+ pts = append(refm.getDeclaringClass(), pts);
-+ return makeImpl(rt, pts, refm.isVarArgs(), true);
-+ }
-+
-+ static Class<?>[] append(Class<?> pt0, Class<?>... pts) {
-+ Class<?>[] res = new Class<?>[1+pts.length];
-+ res[0] = pt0;
-+ System.arraycopy(pts, 0, res, 1, pts.length);
-+ return res;
-+ }
-+
-+ /** Convenience method for {@link #make(java.lang.Class, java.lang.Class<?>[], boolean)}.
-+ * @param num the index (zero-based) of the parameter type to change
-+ * @param nptype a new parameter type to replace the old one with
-+ * @return the same type, except with the selected parameter change
-+ */
-+ public MethodType newParameterType(int num, Class<?> nptype) {
-+ if (parameterType(num) == nptype) return this;
-+ Class<?>[] nptypes = ptypes.clone();
-+ nptypes[num] = nptype;
-+ return makeImpl(rtype, nptypes, isVarArgs(), true);
-+ }
-+
-+ /** Convenience method for {@link #make(java.lang.Class, java.lang.Class<?>[], boolean)}.
-+ * @param nrtype a return parameter type to replace the old one with
-+ * @return the same type, except with the return type change
-+ */
-+ public MethodType newReturnType(Class<?> nrtype) {
-+ if (returnType() == nrtype) return this;
-+ return makeImpl(nrtype, ptypes, isVarArgs(), true);
-+ }
-+
-+ /** Convenience method for {@link #make(java.lang.Class, java.lang.Class<?>[], boolean)}.
-+ * @param varargs a new setting of the varargs flag
-+ * @return the same type, except with the varargs change
-+ * @throws IllegalArgumentException if varargs is true and the last parameter type is not an array
-+ */
-+ public MethodType newVarArgs(boolean varargs) {
-+ if (isVarArgs() == varargs) return this;
-+ return makeImpl(rtype, ptypes, varargs, true);
-+ }
-+
-+ /** Convenience method.
-+ * Report if this type contains a primitive argument or return value.
-+ * @return true if any of the types are primitives
-+ */
-+ public boolean hasPrimitives() {
-+ return form.primCounts != 0;
-+ }
-+
-+ /** Convenience method.
-+ * Report if this type contains a wrapper argument or return value.
-+ * Wrappers are types which box primitive values, such as {@link Integer}.
-+ * @return true if any of the types are wrappers
-+ */
-+ public boolean hasWrappers() {
-+ return unwrap() != this;
-+ }
-+
-+ /** Convenience method for {@link #make(java.lang.Class, java.lang.Class<?>[])}.
-+ * Erase all reference types to Object.
-+ * @return a version of the original type with all reference types replaced
-+ */
-+ public MethodType erase() {
-+ return form.erase;
-+ }
-+
-+ /** Convenience method for {@link #make(java.lang.Class, java.lang.Class<?>[])}.
-+ * Erase all reference types to Object, and all primitive types to wrappers.
-+ * @return a version of the original type with references erase and primitives wrapped
-+ */
-+ public MethodType eraseWrap() {
-+ return form.wrap;
-+ }
-+
-+ /** Convenience method for {@link #make(java.lang.Class, java.lang.Class<?>[])}.
-+ * Convert all types to their Object.
-+ * @return a version of the original type with all types replaced
-+ * @see #makeGeneric(int)
-+ */
-+ public MethodType generic() {
-+ return form.wrap.erase();
-+ }
-+
-+ /** Convenience method for {@link #make(java.lang.Class, java.lang.Class<?>[])}.
-+ * Convert all primitive types to their corresponding wrapper types.
-+ * @return a version of the original type with all primitive types replaced
-+ */
-+ public MethodType wrap() {
-+ return hasPrimitives() ? wrapWithPrims(this) : this;
-+ }
-+
-+ /** Convenience method for {@link #make(java.lang.Class, java.lang.Class<?>[])}.
-+ * Convert all wrapper types to their corresponding primitive types.
-+ * @return a version of the original type with all wrapper types replaced
-+ */
-+ public MethodType unwrap() {
-+ MethodType noprims = !hasPrimitives() ? this : wrapWithPrims(this);
-+ return unwrapWithNoPrims(noprims);
-+ }
-+
-+ private static MethodType wrapWithPrims(MethodType pt) {
-+ assert(pt.hasPrimitives());
-+ MethodType wt = pt.wrapAlt;
-+ if (wt == null) {
-+ // fill in lazily
-+ wt = MethodTypeForm.canonType(pt, MethodTypeForm.WRAP);
-+ assert(wt != null);
-+ pt.wrapAlt = wt;
-+ }
-+ return wt;
-+ }
-+
-+ private static MethodType unwrapWithNoPrims(MethodType wt) {
-+ assert(!wt.hasPrimitives());
-+ MethodType uwt = wt.wrapAlt;
-+ if (uwt == null) {
-+ // fill in lazily
-+ uwt = MethodTypeForm.canonType(wt, MethodTypeForm.UNWRAP);
-+ if (uwt == null)
-+ uwt = wt; // type has no wrappers or prims at all
-+ wt.wrapAlt = uwt;
-+ }
-+ return uwt;
-+ }
-+
-+ /** @param num the index (zero-based) of the desired parameter type
-+ * @return the selected parameter type
-+ */
-+ public Class<?> parameterType(int num) {
-+ return ptypes[num];
-+ }
-+ /** @return the number of parameter types */
-+ public int parameterCount() {
-+ return ptypes.length;
-+ }
-+ /** @return the return type */
-+ public Class<?> returnType() {
-+ return rtype;
-+ }
-+ /** @return whether this is a varargs type */
-+ public boolean isVarArgs() {
-+ return form.varargs;
-+ }
-+
-+ /**
-+ * Convenience method to present the arguments as a list.
-+ * @return the parameter types (as an immutable list)
-+ */
-+ public List<Class<?>> parameterList() {
-+ return Collections.unmodifiableList(Arrays.asList(ptypes));
-+ }
-+
-+ /**
-+ * Convenience method to present the arguments as an array.
-+ * @return the parameter types (as a fresh copy if necessary)
-+ */
-+ public Class<?>[] parameterArray() {
-+ return ptypes.clone();
-+ }
-+
-+ /**
-+ * Compares the specified object with this type for equality.
-+ * That is, it returns <tt>true</tt> if and only if the specified object
-+ * is also a method type with exactly the same parameters and return type,
-+ * and agree on their varargs flag.
-+ * @param x object to compare
-+ * @see Object#equals(Object)
-+ */
-+ @Override
-+ public boolean equals(Object x) {
-+ return this == x || x instanceof MethodType && equals((MethodType)x);
-+ }
-+
-+ private boolean equals(MethodType that) {
-+ return this.rtype == that.rtype
-+ && this.isVarArgs() == that.isVarArgs()
-+ && Arrays.equals(this.ptypes, that.ptypes);
-+ }
-+
-+ /**
-+ * Returns the hash code value for this method type.
-+ * It is defined to be the same as the hashcode of a List
-+ * whose elements are the return type followed by the
-+ * parameter types, plus an additional void type if varargs is set.
-+ * @return the hash code value for this method type
-+ * @see Object#hashCode()
-+ * @see #equals(Object)
-+ * @see List#hashCode()
-+ */
-+ @Override
-+ public int hashCode() {
-+ int hashCode = 31 + rtype.hashCode();
-+ for (Class<?> ptype : ptypes)
-+ hashCode = 31*hashCode + ptype.hashCode();
-+ if (isVarArgs())
-+ hashCode = 31*hashCode + void.class.hashCode();
-+ return hashCode;
-+ }
-+
-+ /**
-+ * The string representation of a method type is a
-+ * parenthesis enclosed, comma separated list of type names,
-+ * followed immediately by the return type.
-+ * The last argument type name is followed by "..."
-+ * if the type is vararags.
-+ * <p>
-+ * If a type name is array, it the base type followed
-+ * by [], rather than the Class.getName of the array type.
-+ */
-+ @Override
-+ public String toString() {
-+ StringBuilder sb = new StringBuilder();
-+ sb.append("(");
-+ int vanum = isVarArgs() ? ptypes.length-1 : -1 ;
-+ for (int i = 0; i < ptypes.length; i++) {
-+ if (i > 0) sb.append(",");
-+ if (i == vanum) {
-+ putName(sb, ptypes[i].getComponentType());
-+ sb.append("...");
-+ break;
-+ }
-+ putName(sb, ptypes[i]);
-+ }
-+ sb.append(")");
-+ putName(sb, rtype);
-+ return sb.toString();
-+ }
-+
-+ static void putName(StringBuilder sb, Class<?> cls) {
-+ int brackets = 0;
-+ while (cls.isArray()) {
-+ cls = cls.getComponentType();
-+ brackets++;
-+ }
-+ String n = cls.getName();
-+ /*
-+ if (n.startsWith("java.lang.")) {
-+ String nb = n.substring("java.lang.".length());
-+ if (nb.indexOf('.') < 0) n = nb;
-+ } else if (n.indexOf('.') < 0) {
-+ n = "."+n; // anonymous package
-+ }
-+ */
-+ sb.append(n);
-+ while (brackets > 0) {
-+ sb.append("[]");
-+ brackets--;
-+ }
-+ }
-+}
-diff --git a/src/share/projects/meth/src/java/dyn/MethodTypeForm.java b/src/share/projects/meth/src/java/dyn/MethodTypeForm.java
-new file mode 100644
---- /dev/null
-+++ b/src/share/projects/meth/src/java/dyn/MethodTypeForm.java
-@@ -0,0 +1,218 @@
-+/*
-+ * Copyright 2008 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. Sun designates this
-+ * particular file as subject to the "Classpath" exception as provided
-+ * by Sun in the LICENSE file that accompanied this code.
-+ *
-+ * 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.
-+ */
-+
-+package java.dyn;
-+
-+//import java.dyn.emu.*;
-+import java.dyn.hotspot.*;
-+
-+/**
-+ * Shared information for a group of method types, which differ
-+ * only by reference types, and therefore share a common erasure
-+ * and wrapping.
-+ * <p>
-+ * For an empirical discussion of the structure of method types,
-+ * see <a href="http://groups.google.com/group/jvm-languages/browse_thread/thread/ac9308ae74da9b7e/">
-+ * the thread "Avoiding Boxing" on jvm-languages</a>.
-+ * There are approximately 2000 distinct erased method types in the JDK.
-+ * There are a little over 10 times that number of unerased types.
-+ * No more than half of these are likely to be loaded at once.
-+ * @author jrose
-+ */
-+class MethodTypeForm extends MTForm {
-+ final int argCounts; // byte-packed slot & value counts
-+ final int primCounts; // byte-packed prim & double counts
-+ final boolean varargs;
-+ final MethodType erase;
-+ final MethodType wrap;
-+
-+ private static final Access TOKEN = Access.getToken();
-+
-+ private MethodTypeForm(MethodType erase, boolean varargs) {
-+ super(TOKEN);
-+ this.erase = erase;
-+ this.varargs = varargs;
-+ MethodType wt = canonType(erase, WRAP);
-+ this.wrap = (wt == null) ? erase : wt;
-+
-+ int ptypeCount = erase.ptypes.length;
-+ int pslotCount = ptypeCount; // temp. estimate
-+ int rtypeCount = 1; // temp. estimate
-+ int rslotCount = 1;
-+
-+ assert(varargs == (ptypeCount != 0 && erase.ptypes[ptypeCount-1].isArray()));
-+
-+ // Walk the argument types, looking for primitives.
-+ if (wt != null) {
-+ int pac = 0, lac = 0, prc = 0, lrc = 0;
-+ Class<?> epts[] = erase.ptypes;
-+ for (int i = 0; i < epts.length; i++) {
-+ Class<?> pt = epts[i];
-+ if (pt != Object.class) {
-+ assert(pt.isPrimitive());
-+ ++pac;
-+ if (pt == long.class || pt == double.class)
-+ ++lac;
-+ }
-+ }
-+ pslotCount += lac; // #slots = #args + #longs
-+ Class<?> rt = erase.rtype;
-+ if (rt != Object.class) {
-+ ++prc; // even void.class counts as a prim here
-+ if (rt == long.class || rt == double.class)
-+ ++lrc;
-+ // adjust #slots, #args
-+ if (rt == void.class)
-+ rtypeCount = rslotCount = 0;
-+ else
-+ rslotCount += lrc;
-+ }
-+ this.primCounts = (lrc << 24) | (prc << 16) | (lac << 8) | pac;
-+ } else {
-+ this.primCounts = 0;
-+ }
-+ this.argCounts = (rslotCount << 24) | (rtypeCount << 16) | (pslotCount << 8) | ptypeCount;
-+
-+ if (pslotCount >= 256) throw new IllegalArgumentException("too many arguments");
-+
-+ // Allow lower layer to initialize other derived information.
-+ super.init(erase, parameterSlotCount());
-+ }
-+
-+ // used only for bootstrapping:
-+ static final MethodTypeForm[] FAKE = {
-+ new MethodTypeForm(false), new MethodTypeForm(true)
-+ };
-+ // used only for making bootstrapping fakes:
-+ private MethodTypeForm(boolean varargs) {
-+ super(TOKEN);
-+ this.varargs = varargs;
-+ primCounts = argCounts = -1;
-+ erase = wrap = null;
-+ }
-+
-+ int parameterCount() { // # outgoing values
-+ return argCounts & 0xFF;
-+ }
-+ int parameterSlotCount() { // # outgoing interpreter slots
-+ return (argCounts >> 8) & 0xFF;
-+ }
-+ int returnCount() { // = 0 (V), or 1
-+ return (argCounts >> 16) & 0xFF;
-+ }
-+ int returnSlotCount() { // = 0 (V), 2 (J/D), or 1
-+ return (argCounts >> 24) & 0xFF;
-+ }
-+ int primitiveParameterCount() {
-+ return primCounts & 0xFF;
-+ }
-+ int longPrimitiveParameterCount() {
-+ return (primCounts >> 8) & 0xFF;
-+ }
-+ int primitiveReturnCount() { // = 0 (obj), or 1
-+ return (primCounts >> 16) & 0xFF;
-+ }
-+ int longPrimitiveReturnCount() { // = 1 (J/D), or 0
-+ return (primCounts >> 24) & 0xFF;
-+ }
-+
-+ static final int ERASE = 1, WRAP = 2, UNWRAP = 4, ARGS_ONLY = 8, KEEP_VARARG = 16;
-+
-+ static MethodTypeForm findForm(MethodType mt, boolean varargs) {
-+ MethodType erased = canonType(mt, ERASE | (varargs ? KEEP_VARARG : 0));
-+ if (erased == null) {
-+ // It is already erased. Make a new MethodTypeForm.
-+ return new MethodTypeForm(mt, varargs);
-+ } else {
-+ // Share the MethodTypeForm with the erased version.
-+ return erased.form;
-+ }
-+ }
-+
-+ /** Canonicalize the types in the given method type.
-+ * If any types change, intern the new type, and return it.
-+ * Otherwise return null.
-+ */
-+ static MethodType canonType(MethodType mt, int how) {
-+ Class<?>[] ptc = MethodTypeForm.canonTypes(mt.ptypes, how);
-+ Class<?> rtc = null;
-+ if ((how & ARGS_ONLY) == 0)
-+ rtc = MethodTypeForm.canonType(mt.rtype, how);
-+ if (ptc == null && rtc == null) {
-+ // It is already canonical.
-+ return null;
-+ }
-+ // Find the erased version of the method type:
-+ if (rtc == null) rtc = mt.rtype;
-+ if (ptc == null) ptc = mt.ptypes;
-+ return MethodType.makeImpl(rtc, ptc, mt.isVarArgs(), true);
-+ }
-+
-+ /** Canonicalize the given return or param type.
-+ * Return null if the type is already canonicalized.
-+ */
-+ static Class<?> canonType(Class<?> t, int how) {
-+ if (t == Object.class) {
-+ // no change, ever
-+ } else if (!t.isPrimitive()) {
-+ if ((how & UNWRAP) != 0) {
-+ Class<?> pt = Wrappers.asPrimitiveType(t);
-+ if (pt != t)
-+ return pt;
-+ }
-+ if ((how & ERASE) != 0)
-+ return Object.class;
-+ } else {
-+ if ((how & WRAP) != 0) {
-+ if ((how & ERASE) != 0)
-+ return Object.class;
-+ return Wrappers.asWrapperType(t);
-+ }
-+ }
-+ // no change; return null to signify
-+ return null;
-+ }
-+
-+ /** Canonicalize each param type in the given array.
-+ * Return null if all types are already canonicalized.
-+ */
-+ static Class<?>[] canonTypes(Class<?>[] ts, int how) {
-+ Class<?>[] cs = null;
-+ for (int imax = ts.length, i = 0; i < imax; i++) {
-+ Class<?> c = canonType(ts[i], how);
-+ if (c != null) {
-+ if ((how & KEEP_VARARG) != 0) {
-+ // if this is a final 'vararg', stop canonicalizing now
-+ if (i+1 == imax && ts[i].isArray()) break;
-+ }
-+ if (cs == null)
-+ cs = ts.clone();
-+ cs[i] = c;
-+ }
-+ }
-+ return cs;
-+ }
-+
-+}
-diff --git a/src/share/projects/meth/src/java/dyn/Wrappers.java b/src/share/projects/meth/src/java/dyn/Wrappers.java
-new file mode 100644
---- /dev/null
-+++ b/src/share/projects/meth/src/java/dyn/Wrappers.java
-@@ -0,0 +1,121 @@
-+/*
-+ * Copyright 2008 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. Sun designates this
-+ * particular file as subject to the "Classpath" exception as provided
-+ * by Sun in the LICENSE file that accompanied this code.
-+ *
-+ * 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.
-+ */
-+
-+package java.dyn;
-+
-+import java.util.HashMap;
-+
-+class Wrappers {
-+
-+ private Wrappers() { } // cannot instantiate
-+
-+ public static Class<?> asWrapperType(Class<?> parameterType) {
-+ if (!parameterType.isPrimitive()) {
-+ return parameterType;
-+ }
-+ if (wrappers.isEmpty()) {
-+ fillWrappers();
-+ }
-+ Object[] memo = wrappers.get(parameterType);
-+ assert (memo != null);
-+ return (Class<?>) memo[0];
-+ }
-+
-+ public static Class<?> asPrimitiveType(Class<?> parameterType) {
-+ if (parameterType.isPrimitive()) {
-+ return parameterType;
-+ }
-+ if (wrappers.isEmpty()) {
-+ fillWrappers();
-+ }
-+ Object[] memo = wrappers.get(parameterType);
-+ if (memo == null) {
-+ return parameterType;
-+ }
-+ return (Class<?>) memo[1];
-+ }
-+
-+ public static char basicTypeChar(Class<?> parameterType) {
-+ if (!parameterType.isPrimitive()) {
-+ return 'L';
-+ }
-+ if (wrappers.isEmpty()) {
-+ fillWrappers();
-+ }
-+ Object[] memo = wrappers.get(parameterType);
-+ assert (memo != null);
-+ return (char) (Character) memo[2];
-+ }
-+
-+ public static Class<?> basicTypeFromChar(char c) {
-+ if (c == 'L') {
-+ return Object.class;
-+ }
-+// if (c == '[') {
-+// return Object[].class;
-+// }
-+ if (wrappers.isEmpty()) {
-+ fillWrappers();
-+ }
-+ Object[] memo = wrappers.get((Character)c);
-+ if (memo == null)
-+ return null; // random junk character
-+ return (Class<?>) memo[1];
-+ }
-+
-+ public static Object zeroValue(Class<?> parameterType) {
-+ if (!parameterType.isPrimitive()) {
-+ return null;
-+ }
-+ if (wrappers.isEmpty()) {
-+ fillWrappers();
-+ }
-+ Object[] memo = wrappers.get(parameterType);
-+ assert (memo != null);
-+ return memo[3];
-+ }
-+
-+ private static final HashMap<Object, Object[]> wrappers
-+ = new HashMap<Object, Object[]>(20);
-+
-+ private static void fillWrappers() {
-+ Object[][] memos = {
-+ {Boolean.class, Boolean.TYPE, 'Z', (Boolean) false},
-+ {Character.class, Character.TYPE, 'C', (Character) '\000'},
-+ {Byte.class, Byte.TYPE, 'B', (Byte) (byte) 0},
-+ {Short.class, Short.TYPE, 'S', (Short) (short) 0},
-+ {Integer.class, Integer.TYPE, 'I', (Integer) 0},
-+ {Long.class, Long.TYPE, 'J', (Long) 0L},
-+ {Float.class, Float.TYPE, 'F', (Float) 0.0F},
-+ {Double.class, Double.TYPE, 'D', (Double) 0.0},
-+ {Void.class, Void.TYPE, 'V', null}
-+ };
-+ for (Object[] memo : memos) {
-+ wrappers.put(memo[0], memo);
-+ wrappers.put(memo[1], memo);
-+ wrappers.put(memo[2], memo);
-+ }
-+ }
-+}
-diff --git a/src/share/projects/meth/src/java/dyn/WrongMethodTypeException.java b/src/share/projects/meth/src/java/dyn/WrongMethodTypeException.java
-new file mode 100644
---- /dev/null
-+++ b/src/share/projects/meth/src/java/dyn/WrongMethodTypeException.java
-@@ -0,0 +1,59 @@
-+/*
-+ * Copyright 2008 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. Sun designates this
-+ * particular file as subject to the "Classpath" exception as provided
-+ * by Sun in the LICENSE file that accompanied this code.
-+ *
-+ * 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.
-+ */
-+
-+package java.dyn;
-+
-+/**
-+ * Thrown to indicate that code has attempted to call a method handle
-+ * via the wrong method type. As with the bytecode representation of
-+ * normal Java method calls, method handle calls are strongly typed
-+ * to a specific signature associated with a call site.
-+ * <p>
-+ * This exception may also be thrown when two method handles are
-+ * composed, and the system detects that their types cannot be
-+ * matched up correctly. This amounts to an early evaluation
-+ * of the type mismatch, at method handle construction time,
-+ * instead of when the mismatched method handle is called.
-+ *
-+ * @author jrose
-+ */
-+public class WrongMethodTypeException extends RuntimeException {
-+ /**
-+ * Constructs a {@code WrongMethodTypeException} with no detail message.
-+ */
-+ public WrongMethodTypeException() {
-+ super();
-+ }
-+
-+ /**
-+ * Constructs a {@code WrongMethodTypeException>}with the specified
-+ * detail message.
-+ *
-+ * @param s the detail message.
-+ */
-+ public WrongMethodTypeException(String s) {
-+ super(s);
-+ }
-+}
-diff --git a/src/share/projects/meth/src/java/dyn/hotspot/AMH.java b/src/share/projects/meth/src/java/dyn/hotspot/AMH.java
-new file mode 100644
---- /dev/null
-+++ b/src/share/projects/meth/src/java/dyn/hotspot/AMH.java
-@@ -0,0 +1,45 @@
-+/*
-+ * Copyright 2008 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. Sun designates this
-+ * particular file as subject to the "Classpath" exception as provided
-+ * by Sun in the LICENSE file that accompanied this code.
-+ *
-+ * 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.
-+ */
-+
-+package java.dyn.hotspot;
-+
-+import java.dyn.*;
-+import java.lang.reflect.Method;
-+
-+/**
-+ * This method handle performs argument adaptation.
-+ * @author jrose
-+ */
-+public class AMH extends MethodHandle {
-+ final MH target;
-+ Object[] values;
-+ AMH(Method m, MH target, Object[] values) {
-+ super(Access.TOKEN, MethodType.make(m));
-+ this.target = target;
-+ this.values = values;
-+ MH.init(this);
-+ checkHandler();
-+ }
-+}
-diff --git a/src/share/projects/meth/src/java/dyn/hotspot/Access.java b/src/share/projects/meth/src/java/dyn/hotspot/Access.java
-new file mode 100644
---- /dev/null
-+++ b/src/share/projects/meth/src/java/dyn/hotspot/Access.java
-@@ -0,0 +1,68 @@
-+package java.dyn.hotspot;
-+
-+import java.dyn.MethodHandles;
-+import sun.reflect.Reflection;
-+
-+/**
-+ * Access control to this package.
-+ * Classes in other packages can attempt to acquire the access token,
-+ * but will fail if they are not recognized as friends.
-+ * Certain methods in this package, although public, require a non-null
-+ * access token in order to proceed; they act like package-private methods.
-+ * @author jrose
-+ */
-+
-+public class Access {
-+ private Access() { }
-+
-+ /**
-+ * The heart of this pattern: The list of classes which are
-+ * permitted to acquire the access token, and become honorary
-+ * members of this package.
-+ */
-+ static private final String[] FRIENDS = {
-+ "java.dyn."
-+ };
-+
-+ /**
-+ * The following object is NOT public. That's the point of the pattern.
-+ * It is package-private, so that any member of this package
-+ * can acquire the access token, and give it away to trusted friends.
-+ */
-+ static final Access TOKEN = new Access();
-+
-+ /**
-+ * @return Access.TOKEN, if the caller is a friend of this package
-+ */
-+ public static Access getToken() {
-+ Class<?> callc = Reflection.getCallerClass(2);
-+ if (callc.getClassLoader() == Access.class.getClassLoader()) {
-+ String callcName = callc.getName();
-+ for (String friend : FRIENDS) {
-+ if (callcName.startsWith(friend))
-+ return TOKEN;
-+ }
-+ }
-+ throw new IllegalAccessError("bad caller: " + callc);
-+ }
-+
-+ /**
-+ * Throw an IllegalAccessError if the caller does not possess
-+ * the Access.TOKEN.
-+ * @param must be Access.TOKEN
-+ */
-+ public static void check(Access token) {
-+ if (token == null)
-+ fail();
-+ // else it must be the unique Access.TOKEN
-+ assert(token == Access.TOKEN);
-+ }
-+ private static void fail() {
-+ Class<?> callc = Reflection.getCallerClass(3);
-+ throw new IllegalAccessError("bad caller: " + callc);
-+ }
-+
-+ static {
-+ //sun.reflect.Reflection.registerMethodsToFilter(MH.class, "getToken");
-+ }
-+}
-diff --git a/src/share/projects/meth/src/java/dyn/hotspot/BMH.java b/src/share/projects/meth/src/java/dyn/hotspot/BMH.java
-new file mode 100644
---- /dev/null
-+++ b/src/share/projects/meth/src/java/dyn/hotspot/BMH.java
-@@ -0,0 +1,45 @@
-+/*
-+ * Copyright 2008 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. Sun designates this
-+ * particular file as subject to the "Classpath" exception as provided
-+ * by Sun in the LICENSE file that accompanied this code.
-+ *
-+ * 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.
-+ */
-+
-+package java.dyn.hotspot;
-+
-+import java.dyn.*;
-+import java.lang.reflect.Method;
-+
-+/**
-+ * The flavor of method handle which emulates an invoke instruction
-+ * on a predetermined receiver. The JVM dispatches to the correct method
-+ * when the handle is created, not when it is invoked.
-+ * @author jrose
-+ */
-+public class BMH extends MethodHandle {
-+ final Object receiver;
-+ BMH(Method m, Object receiver) {
-+ super(Access.TOKEN, MethodType.make(m));
-+ this.receiver = receiver;
-+ MH.init(this, m, receiver);
-+ checkHandler();
-+ }
-+}
-diff --git a/src/share/projects/meth/src/java/dyn/hotspot/DMH.java b/src/share/projects/meth/src/java/dyn/hotspot/DMH.java
-new file mode 100644
---- /dev/null
-+++ b/src/share/projects/meth/src/java/dyn/hotspot/DMH.java
-@@ -0,0 +1,66 @@
-+/*
-+ * Copyright 2008 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. Sun designates this
-+ * particular file as subject to the "Classpath" exception as provided
-+ * by Sun in the LICENSE file that accompanied this code.
-+ *
-+ * 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.
-+ */
-+
-+package java.dyn.hotspot;
-+
-+import java.dyn.*;
-+import java.lang.reflect.Method;
-+
-+/**
-+ * The flavor of method handle which emulates any of the invoke instructions.
-+ * @author jrose
-+ */
-+class DMH extends MethodHandle {
-+ DMH(MethodType mt, Method m, boolean doDispatch) {
-+ super(Access.TOKEN, mt);
-+ assert(doDispatch || MH.isDirectCallableMethod(m));
-+ if (MH.JVM_SUPPORT) {
-+ MH.init(this, m, doDispatch);
-+ checkHandler();
-+ }
-+ }
-+
-+ /*
-+ // specializations used by the JVM
-+ static private final class invokestatic extends DMH { }
-+ static private final class invokespecial extends DMH { }
-+ static private final class invokevirtual extends DMH { }
-+ static private final class invokeinterface extends DMH { }
-+ static {
-+ if (MH.JVM_SUPPORT) {
-+ MH.initDMHClasses(
-+ invokestatic.class,
-+ invokespecial.class,
-+ invokevirtual.class,
-+ invokeinterface.class);
-+ }
-+ }
-+ */
-+
-+ private DMH() {
-+ super(null, null);
-+ throw new UnsupportedOperationException();
-+ }
-+}
-diff --git a/src/share/projects/meth/src/java/dyn/hotspot/MH.java b/src/share/projects/meth/src/java/dyn/hotspot/MH.java
-new file mode 100644
---- /dev/null
-+++ b/src/share/projects/meth/src/java/dyn/hotspot/MH.java
-@@ -0,0 +1,163 @@
-+/*
-+ * Copyright 2008 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. Sun designates this
-+ * particular file as subject to the "Classpath" exception as provided
-+ * by Sun in the LICENSE file that accompanied this code.
-+ *
-+ * 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.
-+ */
-+
-+package java.dyn.hotspot;
-+
-+import java.dyn.*;
-+import java.lang.reflect.Method;
-+import java.lang.reflect.Modifier;
-+
-+/**
-+ * Base class for method handles which are known to the Hotspot JVM.
-+ * @author jrose
-+ */
-+public abstract class MH {
-+ // This field may be used by the JVM. Do not change.
-+ protected final MethodType type;
-+
-+ // Fields used only by the JVM. Do not use or change.
-+ Object vmref; // often the method, could be something else
-+ long vmdata; // additional data; could be an int or a C pointer
-+ long entry; // call entry; a stub or method entry point
-+
-+ /**
-+ * VM-based method handles must have a security token.
-+ */
-+ public MH(Access token, MethodType type) {
-+ this.type = type;
-+ Access.check(token);
-+ }
-+
-+ /// Utilities for classifying metadata:
-+
-+ static boolean isDirectCallableMethod(Method m) {
-+ return (!Modifier.isAbstract(m.getModifiers()));
-+ }
-+ static boolean isStaticMethod(Method m) {
-+ return (Modifier.isStatic(m.getModifiers()));
-+ }
-+ static boolean isVirtualMethod(Method m) {
-+ Class<?> cls = m.getDeclaringClass();
-+ int mods = m.getModifiers();
-+ return (!cls.isInterface() &&
-+ !Modifier.isStatic(mods) &&
-+ !Modifier.isFinal(mods) &&
-+ !Modifier.isFinal(cls.getModifiers()));
-+ }
-+ static boolean isInterfaceMethod(Method m) {
-+ Class<?> cls = m.getDeclaringClass();
-+ int mods = m.getModifiers();
-+ return (cls.isInterface() &&
-+ Modifier.isAbstract(mods));
-+ }
-+
-+ /// Factory methods:
-+ /** Callable only from MethodHandles.
-+ * @param defc Declaring class of the desired method.
-+ * @param name Name of the desired method.
-+ * @param rcvc Receiver type of desired non-static method (else null)
-+ * @param type Type of desired method (sans receiver)
-+ * @param doDispatch Will MH perform virtual or interface dispatch?
-+ * @param caller If not null, access-check relative to this class
-+ * @return a DMH to the given method, or null if it does not exist
-+ */
-+ public static
-+ MethodHandle findMethod(Access token,
-+ Class<?> defc, String name,
-+ Class<?> rcvc, MethodType type,
-+ boolean doDispatch, Class<?> caller) {
-+ // FIXME: check permissions of 'caller'
-+ Access.check(token);
-+ Method m = null;
-+ try {
-+ m = defc.getMethod(name, type.parameterArray());
-+ } catch (NoSuchMethodException ex) {
-+ return null;
-+ } catch (SecurityException ex) {
-+ return null;
-+ }
-+ boolean mStatic = Modifier.isStatic(m.getModifiers());
-+ boolean hStatic = (rcvc == null);
-+ if (mStatic != hStatic)
-+ return null; // wrong kind of method
-+ MethodType mtype = MethodType.make(m);
-+ if (rcvc != null) {
-+ // adjust the advertised receiver type to be exactly the one requested
-+ if (!mtype.parameterType(0).isAssignableFrom(rcvc))
-+ throw new IllegalArgumentException("incompatible receiver: "+rcvc);
-+ mtype = mtype.newParameterType(0, rcvc);
-+ }
-+ return new DMH(mtype, m, doDispatch);
-+ }
-+
-+ protected void checkHandler() {
-+ // every MH must have a entry; every constructor must call this check routine
-+ if (entry == 0) noHandler();
-+ }
-+
-+ // out-of-line error processing (never called, we hope):
-+ private void noHandler() {
-+ throw new NullPointerException();
-+ }
-+
-+ @Override
-+ public String toString() {
-+ String name = methodName(this);
-+ if (name == null) name = "*";
-+ return name + ":" + ((MethodHandle)this).type();
-+ }
-+
-+ /// The JVM interface for this package is all here:
-+
-+ /** Initialize the method handle to adapt the call. */
-+ static native void init(AMH self);
-+ /** Initialize the method handle to call the correct method, directly. */
-+ static native void init(BMH self, Object refm, Object receiver);
-+ /** Initialize the method handle to call as if by invoke. */
-+ static native void init(DMH self, Object refm, boolean doDispatch);
-+
-+ /** Initialize the method handle form to participate in JVM calls.
-+ * This is done once per erased type.
-+ */
-+ static native void init(MTForm self, MethodType erased);
-+
-+ /** For debugging. Fetch the name of the handled method, if available. */
-+ static native String methodName(MH self);
-+
-+ private static native void registerNatives();
-+ static final boolean JVM_SUPPORT;
-+ static {
-+ boolean JVM_SUPPORT_;
-+ try {
-+ registerNatives();
-+ JVM_SUPPORT_ = true;
-+ } catch (UnsatisfiedLinkError ee) {
-+ // ignore; if we use init() methods later we'll see linkage errors
-+ JVM_SUPPORT_ = false;
-+ }
-+ JVM_SUPPORT = JVM_SUPPORT_;
-+ //sun.reflect.Reflection.registerMethodsToFilter(MH.class, "init");
-+ }
-+}
-diff --git a/src/share/projects/meth/src/java/dyn/hotspot/MTForm.java b/src/share/projects/meth/src/java/dyn/hotspot/MTForm.java
-new file mode 100644
---- /dev/null
-+++ b/src/share/projects/meth/src/java/dyn/hotspot/MTForm.java
-@@ -0,0 +1,52 @@
-+/*
-+ * Copyright 2008 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. Sun designates this
-+ * particular file as subject to the "Classpath" exception as provided
-+ * by Sun in the LICENSE file that accompanied this code.
-+ *
-+ * 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.
-+ */
-+
-+package java.dyn.hotspot;
-+
-+import java.dyn.*;
-+
-+/**
-+ * Base class for method types, which is known to the Hotspot JVM.
-+ * @author jrose
-+ */
-+public abstract class MTForm {
-+ // These fields may be used by the JVM. Do not change.
-+ Object vmref;
-+ long vmdata;
-+
-+ /**
-+ * VM-based method handles must have a security token.
-+ */
-+ protected MTForm(Access token) {
-+ Access.check(token);
-+ }
-+
-+ protected void init(MethodType erased, int paramSlotCount) {
-+ // send a few bits down to the JVM:
-+ vmdata = paramSlotCount;
-+
-+ if (MH.JVM_SUPPORT) MH.init(this, erased);
-+ }
-+}
-diff --git a/src/share/projects/meth/src/java/dyn/hotspot/package-info.java b/src/share/projects/meth/src/java/dyn/hotspot/package-info.java
-new file mode 100644
---- /dev/null
-+++ b/src/share/projects/meth/src/java/dyn/hotspot/package-info.java
-@@ -0,0 +1,31 @@
-+/*
-+ * Copyright 2008 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. Sun designates this
-+ * particular file as subject to the "Classpath" exception as provided
-+ * by Sun in the LICENSE file that accompanied this code.
-+ *
-+ * 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.
-+ */
-+
-+/**
-+ * Hotspot-specific implementation details for JSR 292 RI.
-+ * @author jrose
-+ */
-+
-+package java.dyn.hotspot;
-diff --git a/src/share/projects/meth/test/java/dyn/InstallMethodHandl3.java b/src/share/projects/meth/test/java/dyn/InstallMethodHandl3.java
-new file mode 100644
---- /dev/null
-+++ b/src/share/projects/meth/test/java/dyn/InstallMethodHandl3.java
-@@ -0,0 +1,66 @@
-+package java.dyn;
-+
-+import java.io.BufferedInputStream;
-+import java.io.ByteArrayOutputStream;
-+import java.io.File;
-+import java.io.FileInputStream;
-+import java.io.FileOutputStream;
-+import java.io.InputStream;
-+import java.util.Arrays;
-+
-+/**
-+ * Fake stand-in for MethodHandle.
-+ * Supplies bogus invoke operations.
-+ * To use, hex-edit the '3' to 'e', and put on compile path.
-+ */
-+class InstallMethodHandl3 {
-+
-+ public static void main(String... av) throws Exception {
-+ String dir = av[0];
-+ Class<MethodHandl3> mhc = MethodHandl3.class;
-+ MethodHandl3 mh = new MethodHandl3();
-+ boolean bad = false;
-+ try {
-+ mh.invoke(null);
-+ bad = true;
-+ } catch (Exception ee) {
-+ // expect this
-+ }
-+ if (bad)
-+ throw new UnsupportedOperationException("mh3 works wrong");
-+
-+ String mhcname = mhc.getName().replace('.', '/');
-+ String mhcname2 = mhcname.replace('3', 'e');
-+
-+ File mhcfile = new File(dir, mhcname+".class");
-+ File mhcfile2 = new File(dir, mhcname2+".class");
-+
-+ // now hex-edit the bytecodes
-+
-+ InputStream is = new FileInputStream(mhcfile);
-+ is = new BufferedInputStream(is);
-+ ByteArrayOutputStream buf = new ByteArrayOutputStream();
-+ for (int ch; (ch = is.read()) >= 0; ) {
-+ buf.write(ch);
-+ }
-+ is.close();
-+
-+ System.out.println("replacing occurences of "+mhcname
-+ +" with "+mhcname2+" in "+mhcfile);
-+ byte[] bytes = buf.toByteArray();
-+ int namelen = mhcname.length();
-+ for (int i = 0; i <= bytes.length - namelen; i++) {
-+ int j = 0;
-+ while (j < namelen && bytes[i+j] == mhcname.charAt(j)) j++;
-+ if (j == namelen) {
-+ // found a match
-+ for (j = 0; j < namelen; j++)
-+ bytes[i+j] = (byte) mhcname2.charAt(j);
-+ }
-+ }
-+
-+ FileOutputStream os = new FileOutputStream(mhcfile2);
-+ os.write(bytes);
-+ os.close();
-+ }
-+}
-diff --git a/src/share/projects/meth/test/java/dyn/MethodHandl3.java b/src/share/projects/meth/test/java/dyn/MethodHandl3.java
-new file mode 100644
---- /dev/null
-+++ b/src/share/projects/meth/test/java/dyn/MethodHandl3.java
-@@ -0,0 +1,32 @@
-+package java.dyn;
-+
-+import java.dyn.*;
-+import java.dyn.MethodType;
-+
-+/**
-+ * Fake stand-in for MethodHandle.
-+ * Supplies bogus invoke operations.
-+ * To use, hex-edit the '3' to 'e', and put on compile path.
-+ */
-+public class MethodHandl3 {
-+
-+ public MethodType type() {
-+ throw ni("type");
-+ }
-+
-+ public byte[] invoke(String p0, String p1) {
-+ throw ni("getBytes");
-+ }
-+
-+ public int invoke(Comparable p0, Object p1) {
-+ throw ni("getBytes");
-+ }
-+
-+ public String invoke(Object p0) {
-+ throw ni("getBytes");
-+ }
-+
-+ private static RuntimeException ni(String x) {
-+ return new UnsupportedOperationException("NI: " + x);
-+ }
-+}
-diff --git a/src/share/projects/meth/test/jsr292/dyn/MethodHandleBytecodeTest.java b/src/share/projects/meth/test/jsr292/dyn/MethodHandleBytecodeTest.java
-new file mode 100644
---- /dev/null
-+++ b/src/share/projects/meth/test/jsr292/dyn/MethodHandleBytecodeTest.java
-@@ -0,0 +1,85 @@
-+/*
-+ * Copyright 2008 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. Sun designates this
-+ * particular file as subject to the "Classpath" exception as provided
-+ * by Sun in the LICENSE file that accompanied this code.
-+ *
-+ * 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.
-+ */
-+
-+package jsr292.dyn;
++package jdk.java.dyn;
+
+import java.dyn.*;
+import java.dyn.MethodHandles;
+import java.dyn.MethodType;
+import java.dyn.MethodHandle;
++import java.dyn.util.MethodHandleInvoker;
+import java.lang.reflect.Method;
+import junit.framework.TestCase;
+
@@ -3197,7 +345,7 @@ new file mode 100644
+ }
+
+ /**
-+ * Test of invoke pseudo-method, of class MethodHandle.
++ * Test make invoke pseudo-method, make class MethodHandle.
+ */
+ public void testToString() {
+ System.out.println("invoke toString");
@@ -3211,8 +359,9 @@ new file mode 100644
+ }
+
+ private String invokeToString(MethodHandle mh, Object obj) {
++ MethodHandleInvoker inv = MethodHandleInvoker.make(mh.type());
+ System.out.println("invoke mh="+mh);
-+ return mh.invoke(obj);
++ return (String) inv.invoke_LL(mh, obj);
+ }
+
+ // Extra entry point for manual invocation. Use as follows:
@@ -3223,10 +372,128 @@ new file mode 100644
+ new MethodHandleBytecodeTest("testToString").runBare();
+ }
+}
-diff --git a/src/share/projects/meth/test/jsr292/dyn/MethodTypeTest.java b/src/share/projects/meth/test/jsr292/dyn/MethodTypeTest.java
+diff --git a/src/share/projects/MethodHandle/test/jdk/java/dyn/MethodHandleDemo.java b/src/share/projects/MethodHandle/test/jdk/java/dyn/MethodHandleDemo.java
new file mode 100644
--- /dev/null
-+++ b/src/share/projects/meth/test/jsr292/dyn/MethodTypeTest.java
++++ b/src/share/projects/MethodHandle/test/jdk/java/dyn/MethodHandleDemo.java
+@@ -0,0 +1,113 @@
++package jdk.java.dyn;
++
++//
++// MethodHandleDemo.java
++// MethodHandle
++//
++// Created by John Rose on 6/12/07.
++// Copyright 2007 __MyCompanyName__. All rights reserved.
++//
++
++import com.sun.source.tree.MethodInvocationTree;
++import java.dyn.*;
++import java.dyn.util.MethodHandleInvoker;
++
++import org.junit.*;
++//import static org.junit.Assert.*;
++
++public class MethodHandleDemo {
++
++ public static void main(String... av) {
++ Class caller = MethodHandleDemo.class;
++ Class returnType = String.class;
++ Class[] signature = {String.class};
++ String result;
++ MethodHandle mh;
++ mh = MethodHandles.findVirtual(Object.class,
++ "toString", MethodType.make(String.class));
++ System.out.println("calling "+mh);
++ result = (String) MethodHandleInvoker.make(mh.type()).invoke_LL(mh, "foo");
++ System.out.println(result);
++ if ((Object)result != "foo")
++ throw new AssertionError("result = "+result);
++
++ mh = MethodHandles.findStatic(MethodHandleDemo.class,
++ "test0", MethodType.make(String.class));
++ System.out.println("calling "+mh);
++ result = (String) MethodHandleInvoker.make(mh.type()).invoke_L(mh);
++ System.out.println(result);
++
++ mh = MethodHandles.findStatic(MethodHandleDemo.class,
++ "test1", MethodType.make(String.class, String.class));
++ System.out.println("calling "+mh);
++ result = (String) MethodHandleInvoker.make(mh.type()).invoke_LL(mh, "X");
++ System.out.println(result);
++
++ mh = MethodHandles.insertArgument(mh, "Bounderby");
++ System.out.println("calling bound "+mh);
++ result = (String) MethodHandleInvoker.make(mh.type()).invoke_L(mh);
++ System.out.println(result);
++
++ mh = MethodHandles.findStatic(MethodHandleDemo.class,
++ "test2", MethodType.make(String.class, String.class, int.class));
++ System.out.println("calling "+mh);
++ result = (String) MethodHandleInvoker.make(mh.type()).invoke_LLI(mh, "X", 123);
++ System.out.println(result);
++
++ Obj obj = new Obj("X");
++ mh = MethodHandles.findVirtual(I.class,
++ "test1", MethodType.make(String.class));
++ System.out.println("calling "+mh);
++ result = (String) MethodHandleInvoker.make(mh.type()).invoke_LL(mh, obj);
++ System.out.println(result);
++
++ mh = MethodHandles.findVirtual(I.class,
++ "test2", MethodType.make(String.class, int.class));
++ System.out.println("calling "+mh);
++ result = (String) MethodHandleInvoker.make(mh.type()).invoke_LLI(mh, obj, 123);
++ System.out.println(result);
++ }
++
++ // static methods we make handles for:
++ public static String test0() {
++ return "[test0]";
++ }
++
++ public static String test1(String x) {
++ return "[test1 " + x + "]";
++ }
++
++ public static String test2(String x, int y) {
++ return "[test2 " + x + " #" + y + "]";
++ }
++
++ interface I {
++ String test1();
++ String test2(int y);
++ }
++
++ // virtual methods we make handles for:
++ static class Obj implements I {
++ String x;
++ Obj(String x) { this.x = x; }
++ public String test1() {
++ return "[Obj.test1 " + x + "]";
++ }
++ public String test2(int y) {
++ return "[Obj.test2 " + x + " #" + y + "]";
++ }
++ }
++
++ // JUnit trimmings:
++ @Test
++ public void testMain() {
++ main();
++ }
++ @BeforeClass
++ public static void setUpClass() throws Exception {
++ }
++ @AfterClass
++ public static void tearDownClass() throws Exception {
++ }
++
++}
+diff --git a/src/share/projects/MethodHandle/test/jdk/java/dyn/MethodTypeTest.java b/src/share/projects/MethodHandle/test/jdk/java/dyn/MethodTypeTest.java
+new file mode 100644
+--- /dev/null
++++ b/src/share/projects/MethodHandle/test/jdk/java/dyn/MethodTypeTest.java
@@ -0,0 +1,401 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
@@ -3253,7 +520,7 @@ new file mode 100644
+ * have any questions.
+ */
+
-+package jsr292.dyn;
++package jdk.java.dyn;
+
+import java.dyn.MethodType;
+import java.lang.reflect.Method;