--- a/meth.patch Sat Sep 06 20:29:59 2008 -0700
+++ b/meth.patch Sun Sep 07 00:55:33 2008 -0700
@@ -1,496 +1,3 @@ diff --git a/src/share/classes/java/dyn/
-diff --git a/src/share/classes/java/dyn/CallSite.java b/src/share/classes/java/dyn/CallSite.java
-new file mode 100644
---- /dev/null
-+++ b/src/share/classes/java/dyn/CallSite.java
-@@ -0,0 +1,116 @@
-+/*
-+ * 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;
-+
-+/**
-+ * 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>
-+ * @author jrose
-+ */
-+public abstract class CallSite {
-+ protected MethodHandle target;
-+ protected final Object caller; // usually a class
-+ protected final String name;
-+ protected final MethodType type;
-+
-+ protected CallSite(Object caller, String name, MethodType type) {
-+ this.caller = caller;
-+ this.name = name;
-+ this.type = type;
-+ }
-+
-+ /**
-+ * Report the current linkage state of the call site. (This is mutable.)
-+ * The value is null if and only if the call site is currently unlinked.
-+ * @return the current linkage state of the call site
-+ */
-+ public MethodHandle getTarget() {
-+ return target;
-+ }
-+
-+ /**
-+ * Link or relink the call site, by setting its target method.
-+ * @param target the new target, or null if it is to be unlinked
-+ * @throws WrongMethodTypeException if the new target is not null
-+ * and has a method type that differs from the call site type
-+ */
-+ public void setTarget(MethodHandle target) {
-+ checkTarget(target);
-+ this.target = target;
-+ }
-+
-+ protected void checkTarget(MethodHandle target) {
-+ if (!canSetTarget(target))
-+ throw new WrongMethodTypeException(String.valueOf(target));
-+ }
-+
-+ protected boolean canSetTarget(MethodHandle target) {
-+ return (target == null || target.type() == type());
-+ }
-+
-+ /**
-+ * Report the class containing the call site.
-+ * This is immutable static context.
-+ * @return class containing the call site
-+ */
-+ public Class<?> callerClass() {
-+ return (Class) caller;
-+ }
-+
-+ /**
-+ * Report the method name specified in the {@code invokedynamic} instruction.
-+ * This is immutable static context.
-+ * @return method name specified by the call site
-+ */
-+ public String name() {
-+ return 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
-+ */
-+ public MethodType type() {
-+ return type;
-+ }
-+
-+ @Override
-+ public String toString() {
-+ return "CallSite#"+hashCode()+"["+name+type+" => "+target+"]";
-+ }
-+}
-diff --git a/src/share/classes/java/dyn/Dynamic.java b/src/share/classes/java/dyn/Dynamic.java
-new file mode 100644
---- /dev/null
-+++ b/src/share/classes/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 interface Dynamic {
-+ // no methods
-+}
-diff --git a/src/share/classes/java/dyn/Linkage.java b/src/share/classes/java/dyn/Linkage.java
-new file mode 100644
---- /dev/null
-+++ b/src/share/classes/java/dyn/Linkage.java
-@@ -0,0 +1,209 @@
-+/*
-+ * 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.util.MethodHandleInvoker;
-+import java.util.WeakHashMap;
-+import sun.reflect.Reflection;
-+
-+/**
-+ *
-+ * @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.
-+ */
-+ public static
-+ void registerBootstrapMethod(Class callerClass, MethodHandle mh) {
-+ Class callc = Reflection.getCallerClass(2);
-+ checkPackagePrivilege(callc, callerClass, "registerBootstrapMethod");
-+ if (mh != null && mh.type() != BOOTSTRAP_METHOD_TYPE)
-+ throw new WrongMethodTypeException(mh.type().toString());
-+ synchronized (bootstrapMethods) {
-+ if (bootstrapMethods.containsKey(callerClass))
-+ throw new IllegalStateException("bootstrap method already declared in "+callerClass);
-+ bootstrapMethods.put(callerClass, mh);
-+ }
-+ }
-+
-+ /**
-+ * Report the bootstrap method registered for a given class.
-+ * Returns null if the class has never yet registered a bootstrap method,
-+ * or if the class has explicitly registered a null bootstrap method.
-+ * Only callers privileged to set the bootstrap method may inquire
-+ * about it, because a bootstrap method is potentially a back-door entry
-+ * points to its class.
-+ */
-+ public static
-+ MethodHandle getBootstrapMethod(Class callerClass) {
-+ Class callc = Reflection.getCallerClass(2);
-+ checkPackagePrivilege(callc, callerClass, "registerBootstrapMethod");
-+ synchronized (bootstrapMethods) {
-+ return bootstrapMethods.get(callerClass);
-+ }
-+ }
-+
-+ /** The type of any bootstrap method is (CallSite,Object...)Object.
-+ * The varargs marker is required.
-+ */
-+ public static final MethodType BOOTSTRAP_METHOD_TYPE
-+ = MethodType.make(Object.class,
-+ CallSite.class, Object[].class).newVarArgs(true);
-+
-+ private static MethodHandleInvoker bootstrapMethodInvoker;
-+
-+ private static final WeakHashMap<Class, MethodHandle> bootstrapMethods =
-+ new WeakHashMap<Class, MethodHandle>();
-+
-+ /** 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) {
-+ Class callerClass = site.callerClass();
-+ MethodHandle mh;
-+ synchronized (bootstrapMethods) {
-+ mh = bootstrapMethods.get(callerClass);
-+ }
-+ if (mh == null)
-+ throw new IllegalStateException("no bootstrap method declared in "+callerClass);
-+
-+ System.out.println(site+": calling bootstrap "+mh);
-+ if (bootstrapMethodInvoker == null)
-+ bootstrapMethodInvoker = MethodHandleInvoker.make(BOOTSTRAP_METHOD_TYPE);
-+ return bootstrapMethodInvoker.invoke_LLL(mh, site, receiverAndArguments);
-+ }
-+
-+ /**
-+ * 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");
-+ }
-+
-+ /**
-+ * Ensure the requesting class have privileges to perform invokedynamic
-+ * linkage operations on subjectClass. True if requestingClass is
-+ * null (meaning the request originates from the JVM) or if the
-+ * classes are in the same package and have consistent class loaders.
-+ * (The subject class loader must be identical with or be a child of
-+ * the requesting class loader.)
-+ * @param requestingClass
-+ * @param subjectClass
-+ * @return
-+ */
-+ static void checkPackagePrivilege(Class requestingClass, Class subjectClass,
-+ String permissionName) {
-+ if (requestingClass == null) return;
-+ if (requestingClass == subjectClass) return;
-+ SecurityManager security = System.getSecurityManager();
-+ if (security == null) return; // open season
-+ ClassLoader rcl = requestingClass.getClassLoader();
-+ ClassLoader scl = subjectClass.getClassLoader();
-+ if (isParent(rcl, scl)) {
-+ String rn = requestingClass.getName();
-+ if (rn.startsWith("java.dyn.")) return;
-+ String sn = subjectClass.getName();
-+ if (samePackage(rn, sn)) return;
-+ }
-+ security.checkPermission(new LinkagePermission(permissionName, requestingClass));
-+ }
-+
-+ static
-+ MethodHandle findBootstrapMethod(Class callerClass, Class searchBootstrapClass) {
-+ if (searchBootstrapClass != null) throw new UnsupportedOperationException("NYI");
-+ MethodHandle mh = getBootstrapMethod(callerClass);
-+ System.out.println("reporting bootstrap method to JVM: "+mh);
-+ return mh;
-+ }
-+
-+ private static boolean isParent(ClassLoader rcl, ClassLoader scl) {
-+ while (scl != null && scl != rcl)
-+ scl = scl.getParent();
-+ return (scl == rcl);
-+ }
-+
-+ private static boolean samePackage(String rn, String sn) {
-+ assert((rn.indexOf('/') & sn.indexOf('/')) < 0); // no bytecode names
-+ int lastDot = rn.lastIndexOf('.');
-+ if (lastDot != sn.lastIndexOf('.')) return false;
-+ return rn.startsWith(sn.substring(0, lastDot+1));
-+ }
-+
-+}
-diff --git a/src/share/classes/java/dyn/LinkagePermission.java b/src/share/classes/java/dyn/LinkagePermission.java
-new file mode 100644
---- /dev/null
-+++ b/src/share/classes/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/classes/java/dyn/MethodHandle.java b/src/share/classes/java/dyn/MethodHandle.java
new file mode 100644
--- /dev/null
@@ -3021,76 +2528,11 @@ new file mode 100644
+ }
+ }
+}
-diff --git a/src/share/classes/java/dyn/impl/DynCallSite.java b/src/share/classes/java/dyn/impl/DynCallSite.java
-new file mode 100644
---- /dev/null
-+++ b/src/share/classes/java/dyn/impl/DynCallSite.java
-@@ -0,0 +1,60 @@
-+/*
-+ * 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.impl;
-+
-+import java.dyn.*;
-+
-+/**
-+ * The CallSite privately created by the JVM at every invokedynamic instruction.
-+ * @author jrose
-+ */
-+class DynCallSite extends CallSite {
-+ // Fields used only by the JVM. Do not use or change.
-+ Object vmref;
-+ long vmdata;
-+
-+ private DynCallSite(Class<?> caller, String name, MethodType type) {
-+ super(caller, name, type);
-+ }
-+
-+ @Override
-+ public void setTarget(MethodHandle mh) {
-+ checkTarget(mh);
-+ if (MH.JVM_SUPPORT)
-+ MH.linkCallSite(this, mh);
-+ else
-+ super.setTarget(mh);
-+ }
-+
-+ // this is the up-call from the JVM:
-+ static DynCallSite makeSite(Class<?> caller, String name, MethodType type,
-+ long vmdata) {
-+ DynCallSite site = new DynCallSite(caller, name, type);
-+ site.vmdata = vmdata;
-+ System.out.println("DynCallSite: "+site);
-+ return site;
-+ }
-+}
diff --git a/src/share/classes/java/dyn/impl/MH.java b/src/share/classes/java/dyn/impl/MH.java
new file mode 100644
--- /dev/null
+++ b/src/share/classes/java/dyn/impl/MH.java
-@@ -0,0 +1,252 @@
+@@ -0,0 +1,251 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -3323,7 +2765,6 @@ new file mode 100644
+ * The JVM should do this, not the Java code, because vmdata is JVM-private.
+ */
+ static void setVMDataArgSlot(MH self, int argSlot) {
-+ System.out.println("patching vmdata "+Long.toHexString(self.vmdata)+" of "+self);
+ long index = self.vmdata >> 32;
+ self.vmdata = (index << 32) | (argSlot << 32 >>> 32);
+ }
--- a/series Sat Sep 06 20:29:59 2008 -0700
+++ b/series Sun Sep 07 00:55:33 2008 -0700
@@ -1,5 +1,5 @@ anonk.patch #-/anonk #+jdk7-b
-anonk.patch #-/anonk #+jdk7-b30
-meth.patch #-/meth #+jdk7-b30
-#indy.patch #-/indy #+jdk7-b30 #-buildable
-#inti.patch #-/inti #+jdk7-b30 #-buildable
+anonk.patch #-/anonk #+jdk7-b34
+meth.patch #-/meth #+jdk7-b34
+indy.patch #-/indy #+jdk7-b34
+#inti.patch #-/inti #+jdk7-b34 #-buildable
callcc.patch #-/callcc #+jdk7-b30 #-testable
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/indy.patch Sun Sep 07 00:55:33 2008 -0700
@@ -0,0 +1,558 @@
+diff --git a/src/share/classes/java/dyn/CallSite.java b/src/share/classes/java/dyn/CallSite.java
+new file mode 100644
+--- /dev/null
++++ b/src/share/classes/java/dyn/CallSite.java
+@@ -0,0 +1,116 @@
++/*
++ * 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;
++
++/**
++ * 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>
++ * @author jrose
++ */
++public abstract class CallSite {
++ protected MethodHandle target;
++ protected final Object caller; // usually a class
++ protected final String name;
++ protected final MethodType type;
++
++ protected CallSite(Object caller, String name, MethodType type) {
++ this.caller = caller;
++ this.name = name;
++ this.type = type;
++ }
++
++ /**
++ * Report the current linkage state of the call site. (This is mutable.)
++ * The value is null if and only if the call site is currently unlinked.
++ * @return the current linkage state of the call site
++ */
++ public MethodHandle getTarget() {
++ return target;
++ }
++
++ /**
++ * Link or relink the call site, by setting its target method.
++ * @param target the new target, or null if it is to be unlinked
++ * @throws WrongMethodTypeException if the new target is not null
++ * and has a method type that differs from the call site type
++ */
++ public void setTarget(MethodHandle target) {
++ checkTarget(target);
++ this.target = target;
++ }
++
++ protected void checkTarget(MethodHandle target) {
++ if (!canSetTarget(target))
++ throw new WrongMethodTypeException(String.valueOf(target));
++ }
++
++ protected boolean canSetTarget(MethodHandle target) {
++ return (target == null || target.type() == type());
++ }
++
++ /**
++ * Report the class containing the call site.
++ * This is immutable static context.
++ * @return class containing the call site
++ */
++ public Class<?> callerClass() {
++ return (Class) caller;
++ }
++
++ /**
++ * Report the method name specified in the {@code invokedynamic} instruction.
++ * This is immutable static context.
++ * @return method name specified by the call site
++ */
++ public String name() {
++ return 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
++ */
++ public MethodType type() {
++ return type;
++ }
++
++ @Override
++ public String toString() {
++ return "CallSite#"+hashCode()+"["+name+type+" => "+target+"]";
++ }
++}
+diff --git a/src/share/classes/java/dyn/Dynamic.java b/src/share/classes/java/dyn/Dynamic.java
+new file mode 100644
+--- /dev/null
++++ b/src/share/classes/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 interface Dynamic {
++ // no methods
++}
+diff --git a/src/share/classes/java/dyn/Linkage.java b/src/share/classes/java/dyn/Linkage.java
+new file mode 100644
+--- /dev/null
++++ b/src/share/classes/java/dyn/Linkage.java
+@@ -0,0 +1,209 @@
++/*
++ * 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.util.MethodHandleInvoker;
++import java.util.WeakHashMap;
++import sun.reflect.Reflection;
++
++/**
++ *
++ * @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.
++ */
++ public static
++ void registerBootstrapMethod(Class callerClass, MethodHandle mh) {
++ Class callc = Reflection.getCallerClass(2);
++ checkPackagePrivilege(callc, callerClass, "registerBootstrapMethod");
++ if (mh != null && mh.type() != BOOTSTRAP_METHOD_TYPE)
++ throw new WrongMethodTypeException(mh.type().toString());
++ synchronized (bootstrapMethods) {
++ if (bootstrapMethods.containsKey(callerClass))
++ throw new IllegalStateException("bootstrap method already declared in "+callerClass);
++ bootstrapMethods.put(callerClass, mh);
++ }
++ }
++
++ /**
++ * Report the bootstrap method registered for a given class.
++ * Returns null if the class has never yet registered a bootstrap method,
++ * or if the class has explicitly registered a null bootstrap method.
++ * Only callers privileged to set the bootstrap method may inquire
++ * about it, because a bootstrap method is potentially a back-door entry
++ * points to its class.
++ */
++ public static
++ MethodHandle getBootstrapMethod(Class callerClass) {
++ Class callc = Reflection.getCallerClass(2);
++ checkPackagePrivilege(callc, callerClass, "registerBootstrapMethod");
++ synchronized (bootstrapMethods) {
++ return bootstrapMethods.get(callerClass);
++ }
++ }
++
++ /** The type of any bootstrap method is (CallSite,Object...)Object.
++ * The varargs marker is required.
++ */
++ public static final MethodType BOOTSTRAP_METHOD_TYPE
++ = MethodType.make(Object.class,
++ CallSite.class, Object[].class).newVarArgs(true);
++
++ private static MethodHandleInvoker bootstrapMethodInvoker;
++
++ private static final WeakHashMap<Class, MethodHandle> bootstrapMethods =
++ new WeakHashMap<Class, MethodHandle>();
++
++ /** 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) {
++ Class callerClass = site.callerClass();
++ MethodHandle mh;
++ synchronized (bootstrapMethods) {
++ mh = bootstrapMethods.get(callerClass);
++ }
++ if (mh == null)
++ throw new IllegalStateException("no bootstrap method declared in "+callerClass);
++
++ System.out.println(site+": calling bootstrap "+mh);
++ if (bootstrapMethodInvoker == null)
++ bootstrapMethodInvoker = MethodHandleInvoker.make(BOOTSTRAP_METHOD_TYPE);
++ return bootstrapMethodInvoker.invoke_LLL(mh, site, receiverAndArguments);
++ }
++
++ /**
++ * 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");
++ }
++
++ /**
++ * Ensure the requesting class have privileges to perform invokedynamic
++ * linkage operations on subjectClass. True if requestingClass is
++ * null (meaning the request originates from the JVM) or if the
++ * classes are in the same package and have consistent class loaders.
++ * (The subject class loader must be identical with or be a child of
++ * the requesting class loader.)
++ * @param requestingClass
++ * @param subjectClass
++ * @return
++ */
++ static void checkPackagePrivilege(Class requestingClass, Class subjectClass,
++ String permissionName) {
++ if (requestingClass == null) return;
++ if (requestingClass == subjectClass) return;
++ SecurityManager security = System.getSecurityManager();
++ if (security == null) return; // open season
++ ClassLoader rcl = requestingClass.getClassLoader();
++ ClassLoader scl = subjectClass.getClassLoader();
++ if (isParent(rcl, scl)) {
++ String rn = requestingClass.getName();
++ if (rn.startsWith("java.dyn.")) return;
++ String sn = subjectClass.getName();
++ if (samePackage(rn, sn)) return;
++ }
++ security.checkPermission(new LinkagePermission(permissionName, requestingClass));
++ }
++
++ static
++ MethodHandle findBootstrapMethod(Class callerClass, Class searchBootstrapClass) {
++ if (searchBootstrapClass != null) throw new UnsupportedOperationException("NYI");
++ MethodHandle mh = getBootstrapMethod(callerClass);
++ System.out.println("reporting bootstrap method to JVM: "+mh);
++ return mh;
++ }
++
++ private static boolean isParent(ClassLoader rcl, ClassLoader scl) {
++ while (scl != null && scl != rcl)
++ scl = scl.getParent();
++ return (scl == rcl);
++ }
++
++ private static boolean samePackage(String rn, String sn) {
++ assert((rn.indexOf('/') & sn.indexOf('/')) < 0); // no bytecode names
++ int lastDot = rn.lastIndexOf('.');
++ if (lastDot != sn.lastIndexOf('.')) return false;
++ return rn.startsWith(sn.substring(0, lastDot+1));
++ }
++
++}
+diff --git a/src/share/classes/java/dyn/LinkagePermission.java b/src/share/classes/java/dyn/LinkagePermission.java
+new file mode 100644
+--- /dev/null
++++ b/src/share/classes/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/classes/java/dyn/impl/DynCallSite.java b/src/share/classes/java/dyn/impl/DynCallSite.java
+new file mode 100644
+--- /dev/null
++++ b/src/share/classes/java/dyn/impl/DynCallSite.java
+@@ -0,0 +1,60 @@
++/*
++ * 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.impl;
++
++import java.dyn.*;
++
++/**
++ * The CallSite privately created by the JVM at every invokedynamic instruction.
++ * @author jrose
++ */
++class DynCallSite extends CallSite {
++ // Fields used only by the JVM. Do not use or change.
++ Object vmref;
++ long vmdata;
++
++ private DynCallSite(Class<?> caller, String name, MethodType type) {
++ super(caller, name, type);
++ }
++
++ @Override
++ public void setTarget(MethodHandle mh) {
++ checkTarget(mh);
++ if (MH.JVM_SUPPORT)
++ MH.linkCallSite(this, mh);
++ else
++ super.setTarget(mh);
++ }
++
++ // this is the up-call from the JVM:
++ static DynCallSite makeSite(Class<?> caller, String name, MethodType type,
++ long vmdata) {
++ DynCallSite site = new DynCallSite(caller, name, type);
++ site.vmdata = vmdata;
++ System.out.println("DynCallSite: "+site);
++ return site;
++ }
++}